当前位置: 移动技术网 > IT编程>数据库>MSSQL > SQLServr添加数据列

SQLServr添加数据列

2018年08月21日  | 移动技术网IT编程  | 我要评论

晚会开场背景音乐,美女露底,两天一夜090927

数据列定义

表中数据行的数据插入和数据类型都是基于数据列的,学会添加数据列在开发过程中是必不可少的。

使用ssms数据库管理工具添加数据列

在数据表中添加一列或者多列步骤相同

1、连接数据库,选择数据表-》右键点击-》选择设计。

2、在新打开的窗口中输入中-》输入列名,数据类型,是否可空-》在下面输入列注释等属性-》点击保存按钮(或者ctrl+s)。

3、如果想在指定列前面添加数据列-》选择要指定列,右键点击-》插入数据列-》输入列名,列类型,是否可空,属性等,点击保存。

使用t-sql脚本数据列

添加数据列

语法:alter table 数据库名.dbo.表名 add 列名  列类型 [not] null;

示例:

--添加可空数据列
alter table testss.dbo.test1 add height1 nvarchar(50) null;

--添加不可空数据列
alter table testss.dbo.test1 add height2 nvarchar(50) not null;

添加带注释的数据列

 语法:

alter table 数据库名.dbo.表名 add 列名 列数据类型 [not] null;
execute sp_addextendedproperty n'ms_description', n'列说明', n'user', n'dbo', n'table', n'表明, n'column', n'列名';

示例:

alter table testss.dbo.test1 add height3 nvarchar(50) null;
execute sp_addextendedproperty n'ms_description', n'身高3', n'user', n'dbo', n'table', n'test1', n'column', n'height3';

添加数据列时指定默认值

语法:alter table 数据库名.dbo.表名 add 列名 int not null default 值;

示例:alter table testss.dbo.test1 add testid int not null default 1;

添加多个数据列

语法:

alter table 数据库名.dbo.表名 add 列名 列类型 not null default 值,列名 列类型 null default 值;

示例:

alter table testss.dbo.test1 add height5 int not null default 1,
height6 nvarchar(20) null default '178cm';

 

总结

在生产或者开发阶段,数据列的添加建议使用t-sql脚本,方便开发和生产,且易于维护。

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网