Reputation: 3639
I need to do a such thing in SQL but I don't know how...
IF *row exists* THEN
UPDATE ...
ELSE
CREATE ...
I can't figure how to do that..
Upvotes: 0
Views: 560
Reputation: 83699
You can use a normal insert statement with a ON DUPLICATE KEY UPDATE
described in the docs :
here http://dev.mysql.com/doc/refman/5.0/en/insert.html
Upvotes: 0
Reputation: 7212
INSERT ... ON DUPLICATE KEY UPDATE....
or REPLACE
should do the trick:
ON DUPLICATE KEY UPDATE http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
REPLACE http://dev.mysql.com/doc/refman/5.0/en/replace.html
Upvotes: 4