在SQL中如何删除表中的unique属性

alter table student drop unique(sname)
上述语句为什么不能删除表student中的sname列的unique属性。

工具/材料:Management Studio。

1、首先在桌面上,点击“Management Studio”图标。

2、之后在该界面中,右键点击test2表的“设计”选项。

3、接着在该界面中,选中unique属性。

4、然后在该界面中,右键点击“删除列”选项。

5、最后在该界面中,显示删除表中的unique属性后的内容。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-12-16
sql server不支持这种语法,还有一些sql的语法sql server是不支持的,如insert不能一次多条元组等。

sql server中删除约束的语句是:
alter table 表名 drop constraint 约束名

所以要删除约束,首先要知道约束名。
因为你在添加该列时没有指定约束名,即指定了默认值,
因此,sql server将会创建一个依赖于该列的默认约束名。

你在用alter table student drop unique(sname)的时候,
分析器的消息里有写出
“违反了 UNIQUE KEY 约束 '*********' ……”
这里*********就是该列的默认约束名。

另外,也可以通过
sp_helpconstraint student 找到student表的所有列的约束

最后,用
alter table student drop constraint sname列的约束名本回答被提问者采纳
第2个回答  2006-10-05
alter table student drop constraint 约束名