Jörg Reinholz: ON DUPLICATE KEY UPDATE

Beitrag lesen

Moin!

ON DUPLICATE KEY UPDATE K_ID=K_ID

scheint zu machen, was ich vorhabe.

scheint

Kannst Du mir sagen, warum?

Weil es nichts tut. Das hier tut was:

CREATE TABLE `test` (
`id_a` int( 11 ) NOT NULL ,
`id_b` int( 11 ) NOT NULL ,
`data_a` text( 11 ) NOT NULL ,
`data_b` text( 11 ) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET = utf8;

ALTER TABLE `test` ADD UNIQUE (
`id_a` ,
`id_b`
);

INSERT INTO `test` ( `id_a` , `id_b` , `data_a` , `data_b` ) VALUES (
'1', '1', 'foo', 'bar'
);

INSERT INTO `test` ( `id_a` , `id_b` , `data_a` , `data_b` ) VALUES (
'1', '1', 'baz', 'toc'
) ON DUPLICATE KEY UPDATE 
`data_a` = 'baz',
`data_b` = 'toc';

Jörg Reinholz