Sqlite copy table from one database to another

Hi all,
I would like to copy the table structure and fields from one table to another.
Also the resultant table will need some extra fields added to it.

couple ways

  1. use a create table statement that uses an insert http://sqlite.org/lang_createtable.html
    add the extra columns when you write the select statement

  2. create the table with the new structure then INSERT the data using an insert that populates the newly created table

But would this work if I am copying a table from one database into another database.
In Delphi I would copy the Fielddefs from one to another then copy the data from one to another.


you would attach the database:

from here, you should be able to reference both and do as Norm has suggested.

Thanks for that, will give it a test in the morning.

Attach will suffice as long as its another sqlite database

IF you’re trying to copy from different db’s, say Oracle to SQLite, then its a lot more work

tested this but it deletes the table from the source, oops
can I get the fields and the field type from a table then create a new table.
Then do a copy from one to another.


I’d want to see your sql since theres no way that should delete the original table

unless you are executing truncate, delete, or drop… I agree with Norm… something is not right.

Yep, drop was it.
Have had a rethink and i am now using sqlite_master to get all the create table info.
Works well, not pure sqlite but works for me.

Skip dropping the original table and then you can just use the select or create + insert versions