Reputation: 2307
I want create table from another table with constraint?
I used this query "create table destination as select * from source;" fro table creation.
But its copy only the column name in table without column constraint.
Upvotes: 5
Views: 609
Reputation: 21507
There is a special table named sqlite_master
, holding the full CREATE TABLE
statement for each table (it's modified as appropriate during ALTER TABLE
).
I would make my application retrieve that CREATE TABLE
statement:
SELECT sql FROM sqlite_master WHERE type='table' AND name='source';
Then I would replace the table name right after CREATE TABLE
tokens, and execute the result as a new sqlite query.
I don't think that it's possible to do in sqlite's pure SQL without extensions.
Upvotes: 4