MySQL:ALTER IGNORE TABLE ADD UNIQUE,什么会被截断?
我有一个包含 4 列的表:ID、类型、所有者、描述。 ID 是 AUTO_INCRMENT PRIMARY KEY,现在我想:
ALTER IGNORE TABLE `my_table`
ADD UNIQUE (`type`, `owner`);
当然,我有一些类型 = 'Apple' 且所有者 = 'Apple CO' 的记录。所以我的问题是哪一条记录将是 ALTER TABLE 之后保留的特殊记录,是 ID 最小的记录还是最新插入的 ID 最大的记录?
I have a table with 4 columns: ID, type, owner, description. ID is AUTO_INCREMENT PRIMARY KEY and now I want to:
ALTER IGNORE TABLE `my_table`
ADD UNIQUE (`type`, `owner`);
Of course I have few records with type = 'Apple' and owner = 'Apple CO'. So my question is which record will be the special one to stay after that ALTER TABLE, the one with smallest ID or maybe the one with biggest as the latest inserted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 MySQL 5.7.4 开始,
ALTER TABLE
的IGNORE
子句已被删除,并且使用它会产生错误。但对于支持
IGNORE
的旧版本MySQL,将保留第一条记录,其余删除我猜测这里的“第一个”是指具有最小 ID 的值,假设 ID 是主键。
As of MySQL 5.7.4, the
IGNORE
clause forALTER TABLE
is removed and its use produces an error.But for older versions of MySQL that support
IGNORE
, the first record will be kept, the rest deleted §§:I am guessing 'first' here means the one with the smallest ID, assuming the ID is the primary key.
看来您的问题是 ALTER IGNORE 被弃用的原因之一。
这是来自关于 ALTER IGNORE 弃用的 MySQL 注释:
“此功能定义错误(第一行是什么?),会导致问题
对于复制,禁用在线更改以创建唯一索引并具有
导致外键问题(父表中删除的行)。”
It appears that your problem is one of the very reasons that ALTER IGNORE has been deprecated.
This is from the MySQL notes on the ALTER IGNORE deprecation:
"This feature is badly defined (what is the first row?), causes problems
for replication, disables online alter for unique index creation and has
caused problems with foreign keys (rows removed in parent table)."