作者:eggplant | 来源:互联网 | 2023-05-18 04:01
Ihaveacodewithtwomysqlqueries.DELETEFROMmy_tableWHEREuser_idsome_numberINSERTINTOmy_
I have a code with two mysql queries.
DELETE FROM my_table WHERE user_id=some_number
INSERT INTO my_table (user_id, ... ) VALUES(some_number, ...)
我有一个包含两个mysql查询的代码。 DELETE FROM my_table WHERE user_id = some_number INSERT INTO my_table(user_id,...)VALUES(some_number,...)
The field user_id is unique.
字段user_id是唯一的。
In rare cases the insert fails claiming a duplicate entry occurred. My first instinct leads me to to believe the DELETE didn't finish and now the insert is trying to insert and I'm getting a duplicate entry. Is this possible? How can I avoid this? Might there be a different explanation you can think of?
在极少数情况下,插入失败声称发生了重复输入。我的第一直觉让我相信DELETE没有完成,现在插入试图插入,我得到一个重复的条目。这可能吗?我怎么能避免这个?您可以想到有不同的解释吗?
Update: The reason I'm deleting is because I want to delete all the data that I am not updating / inserting for the first time. Also, I think it is important to state that most of the data remains the same.
更新:我删除的原因是因为我想要删除我第一次没有更新/插入的所有数据。此外,我认为重要的是要声明大多数数据保持不变。
5 个解决方案