SQLite Forum

How to create a table as the union of two tables?
Login
If you use `CREATE TABLE ... AS SELECT` then it only uses the column names and expression affinities of the result, and not any primary keys or any other things relevant to the original tables. Sometimes this is what is wanted, but sometimes it might not be.

If you want to make the new table with the same schema as the existing one, then one way might be to read the definition from the schema table, substitute a new table name, and then execute that SQL statement. That cannot be done purely in SQL, but it can be done in a C program.