[MySql] How to make UPDATE to create a row, instead of doing nothing if the row doesnt exist.
#1

As the title says, how can i make an update command to create the row, if the row with the specified ID does not exist?
Reply
#2

You have to check whether the row exists or not. If it doesn't create a new row (INSERT INTO) otherwise just update it (UPDATE). The update statement itself can't create new rows.
Reply
#3

Theres no other way?
Reply
#4

Search for "INSERT … ON DUPLICATE KEY UPDATE"
This one either creates a new row with the given data, or updates the existing one. Exactly what youre looking for I guess.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)