The ALTER DATABASE command enables SQL users to change the overall characteristics and structure of any database. These characteristics are stored in the db.opt file in the database directory.
ALTER DATABASE has many features to alter tables in the databases. These include:
For example, the following table, Student_data
, contains the fields Name
and Age
:
Name | Age |
---|---|
Ali | 19 |
Michael | 21 |
Jason | 20 |
Change the name of the table from Student_data
to College_data
:
ALTER TABLE Student_data;
RENAME College_data;
We want to add a column that shows the status of every student:
ALTER TABLE College_data;
ADD Status varchar(255);
Name | Age | Status |
---|---|---|
Ali | 19 | NULL |
Michael | 21 | NULL |
Jason | 20 | NULL |
Change the name of the column Name
to Student_Name
:
ALTER TABLE College_data;
CHANGE Name Student_Name;
Student_Name | Age | Status |
---|---|---|
Ali | 19 | NULL |
Michael | 21 | NULL |
Jason | 20 | NULL |
Delete the column Status
from our database:
ALTER TABLE College_data;
DROP COLUMN Status;
Name | Age |
---|---|
Ali | 19 |
Michael | 21 |
Jason | 20 |
Free Resources