Custom Search
Showing posts with label The SQL ALTER TABLE Statement. Show all posts
Showing posts with label The SQL ALTER TABLE Statement. Show all posts

Saturday, August 23, 2008

SQL ALTER TABLE

ALTER TABLE

The ALTER TABLE statement is used to add or drop columns in an existing table.

ALTER TABLE table_name 
ADD column_name datatype
ALTER TABLE table_name 
DROP COLUMN column_name

Note: Some database systems don't allow the dropping of a column in a database table (DROP COLUMN column_name).


Person:

LastName FirstName Address
Pettersen Kari Storgt 20


Example

To add a column named "City" in the "Person" table:

ALTER TABLE Person ADD City varchar(30)

Result:

LastName FirstName Address City
Pettersen Kari Storgt 20

Example

To drop the "Address" column in the "Person" table:

ALTER TABLE Person DROP COLUMN Address

Result:

LastName FirstName City
Pettersen Kari