sql server 数据库表中增加列,增加字段,插入列,插入字段,修改列,修改字段,

格式 

--增加列
alter table 表名 
add 字段名 类型 null default 默认值

--给列增加注释
execute sp_addextendedproperty 'MS_Description', 
'列的注释',
'user', 'dbo', 'table', '表名', 'column', '列名'

为SQL Server表中的列添加/修改/删除注释属性sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty_橙cplvfx-技术踩坑记-CSDN博客为SQL Server表中的列添加/修改/删除注释属性 sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedpropertyhttps://cplvfx.blog.csdn.net/article/details/120501336

 下面代码是向 “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

My SQL / Oracle:

ALTER TABLE table_name
MODIFY COLUMN column_name datatype

Oracle 10G 之后版本:

ALTER TABLE table_name
MODIFY column_name datatype;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橙-极纪元JJY.Cheng

客官,1分钱也是爱,给个赏钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值