Create constrained table from another table in sqlite?
I want to create a table from another table with a constraint?
I used this query "create table destination as select * from source"; creating a table.
But it is only copied by the column name in the table without the column constraint.
There is a special table named sqlite_master
that contains the complete statement CREATE TABLE
for each table (it has been modified as needed in ALTER TABLE
).
I would make an application for this operator CREATE TABLE
:
SELECT sql FROM sqlite_master WHERE type='table' AND name='source';
Then I would replace the table name right after the tokens CREATE TABLE
and execute the result as a new sqlite query.
I don't think it can be done in sqlite pure SQL without extensions.