Andreas Korthaus: Gibt es sowas wie UPDATE or INSERT ?

Beitrag lesen

Hallo!

Schau mal, ob dir REPLACE was nutzt.

Ja, dankeschön, das ist genau das gewünschte!

Allerdings löscht REPPLACE die alte Zeile komplett und trägt nur die neuen Daten ein.

Ich gehe mal davon aus dass Du MySQL verwendest. Seit 4.1 gibt es bei INSERT "ON DUPLICATE KEY UPDATE":

If you specify the ON DUPLICATE KEY UPDATE clause (new in MySQL 4.1.0), and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row is performed. For example, if column a is declared as UNIQUE  and contains the value 1, the following two statements have identical effect:

mysql> INSERT INTO table (a,b,c) VALUES (1,2,3)
    -> ON DUPLICATE KEY UPDATE c=c+1;

mysql> UPDATE table SET c=c+1 WHERE a=1;

siehe http://dev.mysql.com/doc/mysql/en/insert.html

Grüße
Andreas

--
SELFHTML Tipps & Tricks: http://aktuell.de.selfhtml.org/tippstricks/