开发者

MySQL Ignore is not working

开发者 https://www.devze.com 2023-03-10 19:07 出处:网络
I am trying to prevent duplicates from occuring using the following query, but it doesnt seem to work. Please could you tell me what the proble开发者_如何学Pythonm is?

I am trying to prevent duplicates from occuring using the following query, but it doesnt seem to work. Please could you tell me what the proble开发者_如何学Pythonm is?

INSERT IGNORE INTO Following SET `followingUserID` = '$accountIDToFollow', `followerUserID` = '$accountID'


INSERT IGNORE INTO 
    Following (`followingUserID`,`followerUserID`) 
VALUE 
   ('$accountIDToFollow','$accountID')

You were doing an UPDATE format before

If you are trying to do an update this is how it works

UPDATE followingUserID SET followingUserID = '$accountIDToFollow', WHERE followerUserID = '$accountID';

Of course you want to replace the were clause with the correct condition you want to do


As per MYSQL documentation,

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.

It means, the IGNORE does not prevent any record duplicate. You will have to put Unique constraints on your given fields.

0

精彩评论

暂无评论...
验证码 换一张
取 消