sqlserver数据库表中增加列,增加字段,插⼊列,插⼊字段,修改
列,修改字段,
格式
--增加列
alter table 表名
add 字段名类型 null default 默认值
--给列增加注释
execute sp_addextendedproperty 'MS_Description',
'列的注释',
'user', 'dbo', 'table', '表名', 'column', '列名'
下⾯代码是向 “Table_1 ”表中增加 "Order"字段,类型为int ,可空,默认值是99
-
-增加列
alter table Table_1
add "Order" int null default 99
--给列增加注释
execute sp_addextendedproperty 'MS_Description',
'排序',
'user', 'dbo', 'table', 'Table_1', 'column', 'Order'
下⾯代码是向 “Table_1 ”表中增加 "age"字段,类型为int ,不能为空
--增加列
alter table Table_1
add age int not null
-
-给列增加注释
execute sp_addextendedproperty 'MS_Description',
'年龄',
'user', 'dbo', 'table', 'Table_1', 'column', 'age'
完整的添加,修改,删除
--添加
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
增加字段的sql语句
My SQL / Oracle:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype
Oracle 10G 之后版本:
ALTER TABLE table_name
MODIFY column_name datatype;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。