0

I have a table in my SQLite database which I need to use as a Template. When the user needs to create a new entry, this template should be displayed. However, the data that is entered should be stored in a table which should ideally have the same structure and keys as the template table. for this to be done, I need to create a new table in the database first which has the same structure, primary key and foreign keys as in the template table. The methods I have tried till now help in creating a new table with the same structure but does not reflect foreign keys as in the original table. How can I do this?

PS: I don't want to use sqlite_master to fetch the table scheme as I will be changing the database later.

Although, other posts suggest the use of 'as select' command, it does copy the table structure alone but fails to include key constraints.

sharpcodes
  • 23
  • 5
  • Creating tables dynamically is generally considered a bad idea - databases scale with rows, not tables. In any case, `sqlite_master` is your only option if you really want to proceed down this route. – Colonel Thirty Two Jun 14 '21 at 13:11
  • Does this answer your question? [Copy table structure to new table in sqlite3](https://stackoverflow.com/questions/12730390/copy-table-structure-to-new-table-in-sqlite3) and [How to copy only the table structure?](https://stackoverflow.com/questions/41312304/how-to-copy-only-the-table-structure) and [Copy table without copying data](https://stackoverflow.com/questions/1834472/copy-table-without-copying-data/18710438) –  Jun 14 '21 at 13:16

0 Answers0