News & UpdatesProgrammingWeb programming Store My Projects

SQL Tutorial – 04 – Alter Drop

Alter Table

The ALTER TABLE statement is used to change columns in a table. To add a column you append the ADD keyword followed by the specifics of the new column.

ALTER TABLE mytable ADD address varchar(30);

To modify a column’s name and data type you append the CHANGE keyword followed by the old name, new name, and data type with attributes.

ALTER TABLE mytable CHANGE address addr char(30);

A column’s data type along with its attributes can be changed with the MODIFY keyword.

ALTER TABLE mytable MODIFY address varchar(100) NOT NULL;

For removing columns there is the DROP keyword.

ALTER TABLE mytable DROP addr;

ALTER TABLE can be used to rename a table with the RENAME TO keywords. This has the same effect as using the RENAME TABLE statement.

RENAME TABLE t1 TO mytable;


The DROP statement can remove database objects. To delete an index you can use the DROP INDEX statement with the name of that index.

DROP INDEX myindex ON mytable;

A table, along with all of its content, can be deleted with the DROP TABLE statement.

DROP TABLE mytable;

An entire database can be deleted with the DROP DATABASE statement.

DROP DATABASE mydatabase;
Recommended additional reading:
Sams - Teach Yourself SQL in 10 Minutes