我希望能够使用“replace into”语句更新具有相同架构的表。最后,我需要能够使用可能已更改的值更新一个大表。
这是我用来开始的查询:
REPLACE INTO table_name
(visual, inspection_status, inspector_name, gelpak_name, gelpak_location),
VALUES (3, 'Partially Inspected', 'Me', 'GP1234', 'A01');
我不明白的是数据库引擎如何知道什么是重复行,什么不是?这些数据非常重要,我不能冒数据被损坏的风险。是否像“如果列出的所有列都具有相同的值,则它是重复行”那么简单?
我只是想找出一种有效的方法来做到这一点,这样我就可以在一分钟内更新超过 45,000 行。
最佳答案
作为 documentation说:
REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.
https://stackoverflow.com/questions/19820724/