MySQL-使现有字段唯一 [英] MySQL - Make an existing Field Unique

查看:69
本文介绍了MySQL-使现有字段唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经存在的表,该表的字段应该唯一,但不是.我只知道这一点,因为在表中创建了一个条目,该条目具有与另一个已经存在的条目相同的值,这导致了问题.

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);


对于MySQL 5.7.4或更高版本:

ALTER TABLE mytbl ADD UNIQUE (columnName);

从MySQL 5.7.4开始,删除了ALTER TABLE的IGNORE子句, 它的使用会产生错误.

As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error.

因此,请确保先删除重复的条目,因为不再支持IGNORE关键字.

So, make sure to remove duplicate entries first as IGNORE keyword is no longer supported.

参考

这篇关于MySQL-使现有字段唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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