问题描述
我有一个已经存在的表,其中的字段应该是唯一的,但不是.我只知道这一点,因为表中的一个条目与另一个已经存在的条目具有相同的值,这导致了问题.
如何让这个字段只接受唯一值?
ALTER IGNORE TABLE mytbl ADD UNIQUE (columnName);<小时>
对于 MySQL 5.7.4 或更高版本:
ALTER TABLE mytbl ADD UNIQUE (columnName);<块引用>
从 MySQL 5.7.4 开始,ALTER TABLE 的 IGNORE 子句被删除,并且它的使用会产生错误.
因此,请务必先删除重复条目,因为不再支持 IGNORE 关键字.
参考
I have an already existing table with a field that should be unique but is not. I only know this because an entry was made into the table that had the same value as another, already existing, entry and this caused problems.
How do I make this field only accept unique values?
ALTER IGNORE TABLE mytbl ADD UNIQUE (columnName);
For MySQL 5.7.4 or later:
ALTER TABLE mytbl ADD UNIQUE (columnName);
As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error.
So, make sure to remove duplicate entries first as IGNORE keyword is no longer supported.
Reference
这篇关于MySQL - 使现有字段唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)