sqlite "replace into"的用法
来源:互联网 发布:淘宝儿童滑板车 编辑:程序博客网 时间:2024/06/08 04:32
http://blog.sina.com.cn/s/blog_590be5290102vulh.html
【举例说明】
建表并插入几条记录:
CREATE TABLE test (id INTEGER PRIMARY KEY, name text, age int, birthday datetime, UNIQUE(name, age));
insert into test (name, age, birthday) values ('aa', 11, '2001-01-01 01:01:01');
insert into test values (5, 'bb', 22, '2002-01-01 01:01:01');
insert into test values (3, 'cc', 33, '2003-01-01 01:01:01');
insert into test values (NULL, 'dd', 44, '2004-01-01 01:01:01');
id
----------
1
3
5
6
1、replace根据UNIQUE约束的字段,确定被替换的是哪一条记录。如果不存在要替换的记录, 那么就会插入一条新的记录。
replace into test values(6, 'ee', '55', '2005-01-01 01:01:01');
id
----------
1
3
5