MySQL Tutorial
ALTER is used to update a Table content.
The ALTER TABLE statement is used to add, modify or delete columns in an existing table. It is also used to rename a table.
You can also use MySQL ALTER TABLE command to add and drop various constraints on an existing table.
ADD is used to add columns into the existing table.
If you want to add columns in MySQL table, the MySQL alter table syntax is given below:
ALTER TABLE table_name
ADD column_name datatype;
The following MySQL adds an "Email" column to the "Students" table:
ALTER TABLE Students
ADD Email varchar(20);
DROP is used to delete columns into the existing table.
If you want to delete columns in MySQL table, the MySQL alter table syntax is given below:
ALTER TABLE table_name
DROP COLUMN column_name;
The following MySQL delete an "Email" column to the "Students" table:
ALTER TABLE Students
DROP COLUMN Email;
ALTER/MODIFY is used to modify columns into the existing table.
If you want to modify columns in MySQL table, the MySQL alter table syntax is given below:
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
The following MySQL modify an "NAME" column to the "Students" table its value of charcter length from 20 to 40.
ALTER TABLE Students
ALTER COLUMN NAME varchar(40);