-1

I used to use UNIQUE KEY id (id) in my table, but whenever a new row with the same id inserted, the new one will be ignored and keep the old row in table.

what I wanna do is to keep the id unique by updating the old row with the new one whenever a new row inserted. Any sugestions?

Pius
  • 614
  • 6
  • 16
  • I guess you are looking for something like `on duplicate key update` ? – Burki Aug 17 '15 at 13:10
  • possible duplicate of [Insert into a MySQL table or update if exists](http://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists) – Toby Speight Aug 17 '15 at 13:14

1 Answers1

0

You can use mysql triggers and do this easily.

A trigger is a set of actions that are run automatically when a specified change operation (SQL INSERT, UPDATE, or DELETE statement) is performed on a specified table. Triggers are useful for tasks such as enforcing business rules, validating input data, and keeping an audit trail.

This link explains on how to achieve this and what are the pros etc..

NaveenKumar
  • 420
  • 1
  • 5
  • 17