Don't ask to ask, just ask | |
PerlMonks |
Re: return primary key if duplicate entry exists?by CountZero (Bishop) |
on Jan 24, 2016 at 09:36 UTC ( [id://1153501]=note: print w/replies, xml ) | Need Help?? |
That SQL will not warn you about duplicate keys. From the MySQL docs: If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row.In other words, the database will delete the existing entry and replace it with the data in the UPDATE statement. If you wish to check if the key already exists then you simply issue a SELECT statement on that key and see if it returns any result. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
In Section
Seekers of Perl Wisdom
|
|