替换为查询语法
我希望能够使用替换为"语句更新相同架构的表.最后,我需要能够使用可能已更改的值更新一个大表.
这是我用来开始的查询:
REPLACE INTO table_name(视觉,检查状态,检查员名称,gelpak_name,gelpak_location),值(3,部分检查",我",GP1234",A01");
我不明白的是数据库引擎如何知道什么是重复行,什么不是?这些数据非常重要,我不能冒数据被破坏的风险.是否像如果列出的所有列具有相同的值,则为重复行"那么简单?
我只是想找出一种有效的方法来做到这一点,这样我就可以在一分钟内更新 > 45,000 行.
解决方案作为文档
a> 说:
<块引用>REPLACE 的工作方式与 INSERT 完全相同,但如果表中的旧行与 PRIMARY KEY 或 UNIQUE 索引的新行具有相同的值,则在插入新行之前删除旧行.
I want to be able to update a table of the same schema using a "replace into" statement. In the end, I need to be able to update a large table with values that may have changed.
Here is the query I am using to start off:
REPLACE INTO table_name
(visual, inspection_status, inspector_name, gelpak_name, gelpak_location),
VALUES (3, 'Partially Inspected', 'Me', 'GP1234', 'A01');
What I don't understand is how does the database engine know what is a duplicate row and what isn't? This data is extremely important and I can't risk the data being corrupted. Is it as simple as "if all columns listed have the same value, it is a duplicate row"?
I am just trying to figure out an efficient way of doing this so I can update > 45,000 rows in under a minute.
解决方案As the documentation says:
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.
相关文章