使用alter table命令将CONSTRAINT添加到表时出错 [英] Getting Error while adding CONSTRAINT to the table using alter table command

查看:265
本文介绍了使用alter table命令将CONSTRAINT添加到表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取错误CREATE UNIQUE INDEX语句终止,因为找到了对象名称'dbo.StudentAdd'和索引名称'ukStIdAdd'的重复键。重复键值为(< null>)。使用alter table命令将CONSTRAINT添加到表中时



Getting Error " The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.StudentAdd' and the index name 'ukStIdAdd'. The duplicate key value is (<null>)." while adding CONSTRAINT to the table using alter table command

Where I tried this command but not working

"ALTER TABLE StudentAdd ADD CONSTRAINT ukStIdd UNIQUE (StIdAdd)"

where StudentAdd is Table Name. ukStIdd Constraint name and StIdd Column Name

推荐答案

The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.StudentAdd' and the index name 'ukStIdAdd'. The duplicate key value is ().



这意味着,在您尝试设置约束时,列中已存在一些重复值。因此,设置约束是不可能的。



你有几种选择:

- 你是否在设置之前消毒你的桌子约束(我的意思是,您要注意在要放置约束的列中没有重复项)。根据桌子的大小,这可能是耗时的。

- 或者你放弃了将这个约束放在这个专栏上的想法。



祝你好运。


This means that, at the time you are trying to set up the constraint, there already are some duplicate values in the column. Thus, it will be impossible to set up the constraint.

You have several choices:
- whether you sanitize your table before setting up the constraint (I mean, you take care that there are no duplicates in the column on which you want to put the constraint). Depending on the size of the table it could be time-costly.
- or you give up the idea to put this constraint on this column.

Good luck.


这篇关于使用alter table命令将CONSTRAINT添加到表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆