The ALTER TABLE
statement in SQL is used to modify the structure of an existing table. It can be used to add, modify, or delete columns, constraints, and indexes.
Syntax:
1 2 3 |
ALTER TABLE table_name [ADD/MODIFY/DROP COLUMN column_name datatype]; |
Example:
1 2 3 |
ALTER TABLE cars ADD COLUMN manufacturer VARCHAR(255); |
In this example, the ALTER TABLE
statement is used to add a new column manufacturer
to the cars
table. The column is of type VARCHAR(255)
, which means it can store string values up to 255 characters in length.
Note: The syntax for the ALTER TABLE
statement may vary depending on the SQL database management system you are using.