当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL Alter
The ALTER TABLE statement is used to add or drop columns in an existing
table.
ALTER 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).
注意:一些数据库系统不允许删除表中的栏目(DROP COLUMN 栏目名)
Person表:
LastName | FirstName | Address |
---|---|---|
Pettersen | Kari | Storgt 20 |
To add a column named "City" in the "Person" table:
给这张"Person"表加一个名为"City"的栏目:
ALTER TABLE Person ADD City varchar(30) |
Result:
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Pettersen | Kari | Storgt 20 |
To drop the "Address" column in the "Person" table:
删除"Person"表中的"Address"栏目
ALTER TABLE Person DROP COLUMN Address |
Result:
结果:
LastName | FirstName | City |
---|---|---|
Pettersen | Kari |