How to drop all empty tables in SQLite?

▼魔方 西西 提交于 2020-01-14 09:35:09

问题


I want to drop all tables that does not have rows.

How to drop all empty tables in SQLite?

EDIT
I need to do this on a mobile phone (no shell there). On a Windows Mobile phone.


回答1:


Tables can be dropped, whether or not they have data in them when the command is executed. Dunno of any database that operates otherwise. So that means:

1) Getting a list of tables -

SELECT name 
  FROM sqlite_master
 WHERE type = 'table'

2) Iterate over that list, using COUNT(*) to determine if any rows exist within a table:

SELECT COUNT(*) 
  FROM ~table

3) If the number returned is less than 1, execute a DROP statement:

DROP TABLE ~table

SQLite doesn't have function or stored procedure support - you'll have to do this from your application.



来源:https://stackoverflow.com/questions/2300080/how-to-drop-all-empty-tables-in-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!