当前位置:数据库 > MySQL >>

MySQL里面的Replace 的用法和insert .. update 的用法

MySQL里面的Replace 的用法和insert .. update 的用法  
drop table if exists t;  
create table t(id int not null auto_increment primary key, name varchar(100));  
create unique index idx_t on t(name);  
replace into t (name) values('first'); -- 数据的id=1  
select * from t;  
replace into t (name) values('first'); -- 数据的id变成了2  
select * from t;  
insert into t(name) values('second'); -- 数据的id为3  
select * from t;  
insert into t(name) values('second') on duplicate key update name='second2'; -- 依然为3,但内容变了  
select * from t; 
MySQL里面的Replace 的用法和insert .. update 的用法

补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,