How to delete all empty tables in SQLITE?

I want to delete all tables without rows.

How to delete all empty tables in SQLite?

Edit
I need to do this on my mobile phone (without casing). On a Windows Mobile phone.

You can delete tables, regardless of whether they contain data when the command is executed. Dunno of any database that operates in other ways. This means:

1) Get a list of tables-

SELECT name 
FROM sqlite_master
WHERE type ='table'

2) Iterate the list, use COUNT(*) to determine whether there are any rows in the table:

SELECT COUNT(*) 
FROM ~table

3) If it returns If the number is less than 1, then execute the DROP statement:

DROP TABLE ~table

SQLite has no function or stored procedure support-you must start from your application Do this.

I want to delete all tables without rows.

How to delete all empty tables in SQLite?

Edit
I need to do this on my phone (without shell). On a Windows Mobile phone.

You can delete the table , Regardless of whether they contain data when the command is executed or not. Dunno of any database that operates in other ways. This means:

1) Get a list of tables –

< /p>

SELECT name 
FROM sqlite_master
WHERE type ='table'

2) Iterate over the list and use COUNT(*) to determine if there are any rows in the table :

SELECT COUNT(*) 
FROM ~table

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

p>

DROP TABLE ~table

SQLite has no function or stored procedure support-you must do this from your application.

Leave a Comment

Your email address will not be published.