开发者

How to drop all empty tables in SQLite?

开发者 https://www.devze.com 2022-12-20 22:07 出处:网络
I want to drop all tables that does not h开发者_开发技巧ave rows. How to drop all empty tables in SQLite?

I want to drop all tables that does not h开发者_开发技巧ave 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消