INSERT ... ON DUPLICATE KEY UPDATE Syntax
2010-06-07 21:07
405 查看
f you specify
,
and a
row is inserted that would cause a duplicate value in a
index or
, an
old row is performed. For example, if column
is declared as
and contains the value
, the
following two
statements have identical effect:
refer to column values from the
to the value of
be inserted, had no duplicate-key conflict occurred. This
function is especially useful in multiple-row inserts. The
only in
returns
otherwise. Example:INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);That statement is identical to the following two statements:INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=3;
INSERT INTO table (a,b,c) VALUES (4,5,6)
ON DUPLICATE KEY UPDATE c=9;
ON DUPLICATE KEY UPDATE
,
and a
row is inserted that would cause a duplicate value in a
UNIQUE
index or
PRIMARY KEY
, an
UPDATEof 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;You can use the
VALUES(function in thecol_name)
UPDATEclause to
refer to column values from the
INSERTportion of the
INSERT ... ON DUPLICATE KEY UPDATEstatement. In other words,
VALUES(in thecol_name)
ON DUPLICATE KEY UPDATEclause refers
to the value of
col_namethat would
be inserted, had no duplicate-key conflict occurred. This
function is especially useful in multiple-row inserts. The
VALUES()function is meaningful
only in
INSERT ... UPDATEstatements and
returns
NULL
otherwise. Example:INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);That statement is identical to the following two statements:INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=3;
INSERT INTO table (a,b,c) VALUES (4,5,6)
ON DUPLICATE KEY UPDATE c=9;
相关文章推荐
- INSERT ... ON DUPLICATE KEY UPDATE Syntax
- INSERT ... ON DUPLICATE KEY UPDATE Syntax
- INSERT ... ON DUPLICATE KEY UPDATE Syntax
- MySQL的Replace into 与Insert into on duplicate key update真正的不同之处
- mysql中INSERT INTO… ON DUPLICATE KEY UPDATE用法
- Mysql中Insert into xxx on duplicate key update
- MySql避免"重复插入记录"的方法(INSERT ignore into,Replace into,ON DUPLICATE KEY UPDATE)
- INSERT ... ON DUPLICATE KEY UPDATE
- MySQL中insert ignore into, on duplicate key update,replace into,insert … select … where not exist的一些用法总结
- (转载)[MySQL技巧]INSERT INTO… ON DUPLICATE KEY UPDATE
- mysql重复插入insert时更新ON DUPLICATE KEY UPDATE
- MySQL insert ignore into、replace into、insert into、on duplicate key update 详解
- 有关sql语句INSERT INTO ..ON DUPLICATE KEY UPDATE..的详解
- MySql中4种批量更新的方法update table2,table1,批量更新用insert into ...on duplicate key update, 慎用replace into.
- MySQL的Replace into 与Insert into ..... on duplicate key update ...真正的不同之处
- MySQL的Replace into 与Insert into on duplicate key update真正的不同之处
- MySQL的Replace into 与Insert into ..... on duplicate key update ...真正的不同之处
- insert ... on duplicate key update 性能
- 【转】MySQL的Replace into 与Insert into on duplicate key update真正的不同之处
- MySQL的Replaceinto与Insertinto.....onduplicatekeyupdate...真正的不同之处