Mysql function: Insert if not exist or updated
I am having a small problem- How would I write a function in mysql to insert a record if it doesn't exist or if its a case where it exists then say for example the record is updated a fresh copy of the default record should be reinserted leaving the updated record in the table. Let me give a small scenario, please read carefully before bashing me, I'm trying to explain as best as I can:
table name= Computer. Columns(2) = comp_id(Auto-increment), comp_name.
Default Data I'd want to be in the table=
comp_id= 1, comp_name='Dell'
Now if I should Update this information to:
The function should automatically add the previous record which was:
I thought of using update if not exist but I was reading a blog and they stated Mysql does not support update if not exist. If you could provide any suggestions I'd really appreciate, Thanks.
You want INSERT ON DUPLICATE UPDATE in mysql.