SQL ALTER TABLE Syntax and instance tutorial
The ALTER TABLE statement allows you to change the structure of a table after it has been created. New column can be added to the address clause. Existing columns may be deleted from the list of drop clauses used.
The syntax for the ALTER TABLE statement is as follows:
ALTER TABLE table_name
ADD column_name Data_type
ALTER TABLE table_name
DROP COLUMN column_name
Note: The ALTER table statement is not part of the Ansi/iso standard. This means that all SQL implements different terms and commands syntax for commercial dialects.
Example #
ALTER TABLE Orders
ADD Quantity SMALLINT
This example adds a column to the order table by specifying the name and data type of the new column.
Sample case
ALTER TABLE employeeaddresstable
ADD Description VARCHAR DEFAULT ' USA ' not NULL
This example adds a column named "description" to the Employeeaddresstable table. We also add reserved words that are NOT NULL, require valid data to be added to the column, and specify a default value.
such as #3
ALTER TABLE antiqueowners DROP COLUMN State