On Thu, May 17, 2012 at 11:36:53AM +0200, Luuk scratched on the wall: > On 17-05-2012 11:04, YAN HONG YE wrote: > > I have two db files: > > > > sqlite3 *db1; > > sqlite3 *db2; > > rc1 = sqlite3_open("myfile1", &db1); > > rc2 = sqlite3_open("myfile2", &db2); > > > > I want to copy db1.table1 to db2 file, but I don't know how to do? > > sqlite myfile1 > sqlite> attach database 'myfile2' as db2; > sqlite> create table db2.table1 as select * from main.table1;
Generally you want to create the table manually and then copy the data with "INSERT INTO db2.table1 SELECT * FROM main.table1;" or something similar. You can get the original CREATE TABLE statement from the sqlite_master table. Creating the table with CREATE TABLE...AS SELECT will not preserve PKs or any other constraints. Newer versions of SQLite will attempt to preserve the column affinities, but, IIRC, older version will not (and all columns will have a NONE affinity). CREATE TABLE...AS SELECT is great for temp tables, but it is not a useful way to truly "copy" a table. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable." -- Angela Johnson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users