如何在SQLite中删除所有空表? [英] How to drop all empty tables in SQLite?
问题描述
我想删除所有没有行的表.
I want to drop all tables that does not have rows.
如何在SQLite中删除所有空表?
How to drop all empty tables in SQLite?
编辑
我需要在手机(没有外壳)上执行此操作.在Windows Mobile手机上.
EDIT
I need to do this on a mobile phone (no shell there). On a Windows Mobile phone.
推荐答案
可以删除表,无论执行命令时表中是否有数据.任何以其他方式运行的数据库的Dunno.因此,意味着:
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)获取表列表-
SELECT name
FROM sqlite_master
WHERE type = 'table'
2)使用COUNT(*)遍历该列表,以确定表中是否存在任何行:
2) Iterate over that list, using COUNT(*) to determine if any rows exist within a table:
SELECT COUNT(*)
FROM ~table
3)如果返回的数字小于1,请执行DROP语句:
3) If the number returned is less than 1, execute a DROP statement:
DROP TABLE ~table
SQLite不具有功能或存储过程支持-您必须在应用程序中执行此操作.
SQLite doesn't have function or stored procedure support - you'll have to do this from your application.
这篇关于如何在SQLite中删除所有空表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!