sqlite如何一次查询多个数据文件中的数据

sqlite如何一次查询多个数据文件中的数据

尽管SQLite的单个文件大小可以达到(2G或是2T),但有时人们还是会将数据保存在不同的数据文件中,这个时候如果想通过一句SQL将这些数据查出了,该怎么办呢?
幸运的是,SQLite中可以附加其它SQLite数据文件,这样一来我们就可以通过UNION ALL将它们一起查出了。
现附一例。如下:
e.g.
~@chinacom$sqlite3 test.dbf
create table test(id int,name varchar(256));
insert into test(id,name) values(1,'one');
insert into test(id,name) values(2,'two');
insert into test(id,name) values(3,'three');
sql>.q

~@chinacom$sqlite3 dummy.dbf
create table test(id int,name varchar(256));
insert into test(id,name) values(1,'one');
insert into test(id,name) values(2,'two');
sql>[b]attach database 'test.dbf' as dev;[/b]
sql>select * from dev.test;
sql>.header on
sql>select a.id as id2,a.name as name2,b.id,b.name from test a,dev.test b where a.id=b.id;
sql>select * from test union all select * from dev.test;

posted on 2008-02-27 15:50  步走高飞  阅读(896)  评论(0编辑  收藏  举报

导航