parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

есть несколько вариантов

Sergey M. 12.05.2006 12:37

http://dev.mysql.com/doc/refman/4.1/en/replace.html

почти то же самое, только более по стандартам, более хитрый синтаксис но вроде в более поздних версиях появилось:
http://dev.mysql.com/doc/refman/4.1/en/insert-on-duplicate.html

если нужно вставить не одну строку а пачку записей, то
http://dev.mysql.com/doc/refman/4.1/en/load-data.html
см. опции [REPLACE | IGNORE]

во всех случаях нужно, чтобы в таблице были столбцы либо с PRIMARY KEY либо declared as UNIQUE, по произвольному условию не сработает.
MySQL uses the following algorithm for REPLACE (and LOAD DATA ... REPLACE): 

 1. Try to insert the new row into the table 

 2. While the insertion fails because a duplicate-key error occurs for a primary key or unique index: 

    a. Delete from the table the conflicting row that has the duplicate key value 

    b. Try again to insert the new row into the table