SQL server中对字段的( alter)修改、删除、添加、双主键、多主键、获取一列不重复的字段

﹥>﹥吖頭↗ 提交于 2020-10-25 12:35:19

1.修改字段长度

alter table 表名 alter column 表字段 nvarchar(300) not null

2.删除字段

alter table 表名 drop column 表字段

3.添加字段

alter table 表名 add 表字段 nvarchar(2) not null

4.修改字段名

alter table 表名 rename column 原字段 to 修改字段

5.创建双主键(前提条件主键字段不能为空)

alter table 表名with nocheck add
constratint 主键名字 primary key nonclustered(
[字段1],
[字段2]
)



6.创建多主键(前提条件主键字段不能为空)

alter table 表名with nocheck add
constratint 主键名字 primary key nonclustered(
[字段1],
[字段2],

[字段n]
)





7.去掉一列的重复数据

select distinct 字段名 FROM 数据表名

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!