Insert into mysql table and overwrite any current data

I insert some data into the table, but sometimes it encounters other data in the table (i.e. it has the same primary key).
I would like to be able to simply overwrite this data, if there is one, instead of having mysql send me an error message saying that this is a duplicate of the primary key. I know that I can simply delete these values ​​before starting work, but this will require a somewhat large query.
Is it possible to somehow overwrite them and stop any warnings, or am I forced to delete these values.

+5
source share
5 answers

just a little cheatsheet
Mysql has 3 different primary key processing scenarios:
if you want ...

+13
source

In MySQL there is a command "INSERT ... TO DUPLICATE KEY". You can find it here: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

INSERT INTO `table` VALUES ('a', 'b') ON DUPLICATE KEY UPDATE `field1`='a', `field2`='b'
+3
source

REPLACE INTO MySQL .

REPLACE INTO table
SET name = 'Treffynnon'
+2

You can use replace instead of paste . Take a look at http://dev.mysql.com/doc/refman/5.1/en/replace.html

0
source

All Articles