ALTER TABLE
The ALTER TABLE statement is used to add or drop columns in an existing table.
ALTER TABLE table_name ALTER TABLE table_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 |
No comments:
Post a Comment