gpt4 book ai didi

MySQL v5.7.4 - 是否不再可以使用 "unique index"删除重复项?

转载 作者:行者123 更新时间:2023-11-29 11:29:58 26 4
gpt4 key购买 nike

很明显,在 mySQL v5.7.4 之后,不再支持关键字 IGNORE,这会破坏这个有用的重复删除查询:

alter IGNORE table labs 
add unique index noDUPES (ruid, test_sname, test_value, units, ref_range, entry_date);

我看过的所有地方都指出已停止支持 IGNORE,但不建议进行替代。

在 mySQL v5.7.4 之后,是否仍然有一种简单的方法可以利用 UNIQUE INDEX 的功能来删除重复项,而无需使用 IGNORE

最佳答案

许多人认为创建索引不会从基础表中删除记录是一件好事。一种方法是使用临时表、截断和插入:

create temporary table tokeep as
select distinct ruid, test_sname, test_value, units, ref_range, entry_date
from labs;

truncate table labs;

insert into labs(ruid, test_sname, test_value, units, ref_range, entry_date)
select ruid, test_sname, test_value, units, ref_range, entry_date
from tokeep;

注意:此版本假定这些是表中唯一的列。如果还有其他列,类似的逻辑也会起作用。

关于MySQL v5.7.4 - 是否不再可以使用 "unique index"删除重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37581292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com