简体   繁体   English

SQL 错误 [1064] [42000]:在 Z81C3B080DAD537DE7EZE10E0987A4BF58 上使用 ALTER IGNORE TABLE 时,您的 SQL 语法有错误

[英]SQL Error [1064] [42000]: You have an error in your SQL syntax when using ALTER IGNORE TABLE on mysql 8

This one works in older mysql versions, but the good thing with this query is that it will remove duplicates and same time add index, how do i do the same in mysql 8 commercial这适用于较旧的 mysql 版本,但此查询的好处是它将删除重复项并同时添加索引,我如何在 mysql 8 商业版中执行相同操作

ALTER IGNORE TABLE tablex
ADD UNIQUE INDEX id_rmd (field1,field12, field3);

SQL Error [1064] [42000]: You have an error in your SQL syntax; SQL 错误 [1064] [42000]:您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IGNORE TABLE...检查与您的 MySQL 服务器版本相对应的手册,以获取在“忽略表...”附近使用的正确语法

How do i do the same in mysql 8 commercial.我如何在 mysql 8 商业版中做同样的事情。 ie remove duplicate while same time create index即删除重复的同时创建索引

Commercial or not doesn't make a difference.商业与否并不重要。 This 5.6 and earlier feature is removed in later versions.此 5.6 及更早版本的功能已在更高版本中删除。

https://dev.mysql.com/doc/refman/5.6/en/alter-table.html : https://dev.mysql.com/doc/refman/5.6/en/alter-table.html

IGNORE is a MySQL extension to standard SQL. IGNORE 是标准 SQL 的 MySQL 扩展。 It controls how ALTER TABLE works if there are duplicates on unique keys in the new table or if warnings occur when strict mode is enabled.如果新表中的唯一键有重复项或启用严格模式时出现警告,它会控制 ALTER TABLE 的工作方式。 If IGNORE is not specified, the copy is aborted and rolled back if duplicate-key errors occur.如果未指定 IGNORE,则如果发生重复键错误,则副本将中止并回滚。 If IGNORE is specified, only one row is used of rows with duplicates on a unique key.如果指定了 IGNORE,则仅使用在唯一键上有重复的行中的一行。 The other conflicting rows are deleted.其他冲突的行被删除。 Incorrect values are truncated to the closest matching acceptable value.不正确的值将被截断为最接近的匹配可接受值。

You can just rename and copy the table (untested):您可以重命名并复制表(未经测试):

create tablex_new like tablex;
ALTER TABLE tablex_new
ADD UNIQUE INDEX id_rmd (field1,field12, field3);
insert ignore into tablex_new select * from tablex;
rename tablex to tablex_old, tablex_new to tablex;
drop table tablex_old;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM