格式
alter table 表名 add 字段名 类型 null default 默认值
下面代码是向 “Table_1 ”表中增加 "Order"字段,类型为int ,可空,默认值是99
alter table Table_1 add "Order" int null default 99
下面代码是向 “Table_1 ”表中增加 "age"字段,类型为int ,不能为空
alter table Table_1 add age int not null
完整的添加,修改,删除
--添加 alter table Table_1 add msg nchar(10) null --修改 alter table Table_1 alter column msg nvarchar(500) null --删除 alter table Table_1 drop column msg
格式说明
--添加 alter table 表名 add 字段名 类型 是否空 --修改 alter table 表名 alter column 字段名 类型 是否空 --删除 alter table 表名 drop column 字段名
延伸阅读
SQL ALTER TABLE 语句
ALTER TABLE 语句
ALTER TABLE 语句用于在已有的表中添加、删除或修改列。
SQL ALTER TABLE 语法
添加
如需在表中添加列,请使用下面的语法:
ALTER TABLE table_name ADD column_name datatype
删除
如需删除表中的列,请使用下面的语法(请注意,某些数据库系统不允许这种在数据库表中删除列的方式):
ALTER TABLE table_name DROP COLUMN column_name
修改
要改变表中列的数据类型,请使用下面的语法:
SQL Server / MS Access:
ALTER TABLE table_name ALTER COLUMN column_name datatype
My SQL / Oracle:
ALTER TABLE table_name MODIFY COLUMN column_name datatype
Oracle 10G 之后版本:
ALTER TABLE table_name MODIFY column_name datatype;