MySQL中详细update (on duplicate key update id=values(id),value=values(value)......) (转)
2012-02-27 17:26
549 查看
MySQL中详细update (on duplicate key update id=values(id),value=values(value)......)
use test;drop table if exists test.test;
CREATE TABLE `test` (
`id` tinyint(4) NOT NULL,
`value` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into test.test(id,value) values(1,"first"),(2,"second"),(3,"third");
select * from test.test;
/**
'1', 'first'
'2', 'second'
'3', 'third'
*/
-- 方案1
insert into test(id,value) values(1,"11first"),(2,"22second"),(3,"33third") on duplicate key update id=values(id),value=values(value);
-- 方案2
select * from test.test;
replace into test(id,value) values(1,"11first"),(2,"22second"),(3,"33third");
select * from test.test;
/**
-- 看结果已经改变了
'1', '11first'
'2', '22second'
'3', '33third'
*/
相关文章推荐
- MySQL中详细update (on duplicate key update id=values(id),value=values(value)......)
- mysql中insert...on duplicate key update...使用
- MySQL插入或更新 ON DUPLICATE KEY UPDATE
- Mysql ON DUPLICATE KEY UPDATE 的 用法 简记
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
- 深入mysql "ON DUPLICATE KEY UPDATE" 语法的分析
- MySql插入数据重复,Duplicate entry 'value' for key 'user_id'
- mysql重复插入insert时更新ON DUPLICATE KEY UPDATE
- MySql中ON DUPLICATE KEY UPDATE用法解析
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
- MySQL的Replace into 与Insert into on duplicate key update真正的不同之处
- mysql insert的几点操作(DELAYED,IGNORE,ON DUPLICATE KEY UPDATE )
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
- MySQL中ON DUPLICATE KEY UPDATE使用
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
- mysql 批量更新语句 INSERT ON DUPLICATE KEY UPDATE
- mysql insert into on duplicate key update timestamp类型 (近期遇到问题)
- 深入mysql insert table ... "ON DUPLICATE KEY UPDATE" 语法的分析
- mysql on duplicate key update 的坑