如何在创建表之后将密钥声明为唯一 [英] How to declare a key as unique after table is created

查看:54
本文介绍了如何在创建表之后将密钥声明为唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的语句中写了将 IFSC_CODE 声明为 unique ,但是下面的语句不允许声明它。



如果有人有解决方案,请帮助我。

I have written below statement to declare my IFSC_CODE as unique, but below statement do not allow to declare it.

If anyone has solution please help me.

ALTER TABLE bank_master
add CONSTRAINT Ifsc_Code_unique UNIQUE (IFSC_CODE);

推荐答案

来自例外,很明显已经有重复的值。

当你改变了并使 UNIQUE ,因此违反了。



如果你想把它变成 UNIQUE ,那么在删除重复的条目后再尝试。
From the Exception, it is quite clear that the Column already have duplicate values in it.
As you are altering the Table and making the Column UNIQUE, so it is violating.

If you want to make it UNIQUE, then try after removing the duplicate entries.


这里你试图创建一个唯一约束。



尝试创建一个具有唯一约束的非唯一索引并查看它是否有效。
Here you are trying to create a Unique constraint.

Try creating a Non-unique index with a unique constraint and see if it works.


阅读完所有评论和y后我们的查询改变约束并尝试从我的结束。

我可以说你正在使用的表已经有数据(重复数据)

和按照< b>唯一键约束在该列中输入的所有值必须是唯一的

Null也是唯一的,但Null也不能多次输入。

所以我建议你删除该列的所有重复条目并尝试。



祝你好运
After reading all the comments and your query to alter the constraint and trying from my end.
I can say that the table which you are using is already having data (duplicate data)
and as per Unique key constraint all the values entered in that column must be unique
Null is also is unique but Null also can not be entered more than once
.
So i would suggest you delete all duplicate entries for that column and try.

Good luck


这篇关于如何在创建表之后将密钥声明为唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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