Drop all tables command

后端 未结 10 579
滥情空心
滥情空心 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:58

    While it is true that there is no DROP ALL TABLES command you can use the following set of commands.

    Note: These commands have the potential to corrupt your database, so make sure you have a backup

    PRAGMA writable_schema = 1;
    delete from sqlite_master where type in ('table', 'index', 'trigger');
    PRAGMA writable_schema = 0;
    

    you then want to recover the deleted space with

    VACUUM;
    

    and a good test to make sure everything is ok

    PRAGMA INTEGRITY_CHECK;
    

提交回复
热议问题