Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Działanie on duplicate key update...
-Zsert-
post
Post #1





Goście







Czy on duplicate key update działa tak samo jak UPDATE tzn że aktualizuje rekordy ale o tym samym id czy działa jak replace tzn kasuje wskazany rekord i zapisuje jako rekord o innym id np. mam jakiś rekord o id 1 replace robi tak że kasuje ten rekord o id 1 i dodaje nowy o id 2. Jak działa on duplicate key update?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




http://dev.mysql.com/doc/refman/5.0/en/ins...-duplicate.html

Cytat
If you specify ON DUPLICATE KEY UPDATE, 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:

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

UPDATE table SET c=c+1 WHERE a=1;
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 20:46