Drop all tables command

后端 未结 10 580
滥情空心
滥情空心 2020-11-28 23:52

What is the command to drop all tables in SQLite?

Similarly I\'d like to drop all indexes.

10条回答
  •  一生所求
    2020-11-28 23:55

    I can't say this is the most bulletproof or portable solution, but it works for my testing scripts:

    .output /tmp/temp_drop_tables.sql
    select 'drop table ' || name || ';' from sqlite_master where type = 'table';
    .output stdout
    .read /tmp/temp_drop_tables.sql
    .system rm /tmp/temp_drop_tables.sql
    

    This bit of code redirects output to a temporary file, constructs the 'drop table' commands that I want to run (sending the commands to the temp file), sets output back to standard out, then executes the commands from the file, and finally removes the file.

提交回复
热议问题