Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: Conditional DDL Statements

Tags:

sqlite

ddl

I wish to execute the following type of code in sqlite3:

drop table x if (select y from z where col1 = "a");

Essentially execute DDL commands IF certain values exist currently in the same database.

Any ideas?

like image 476
abhishekbh Avatar asked Jun 28 '26 17:06

abhishekbh


1 Answers

A sqlite shell script:

.bail ON
SELECT CASE COUNT(*)
       WHEN 0       THEN 1/0  -- will throw
       ELSE 1
       END
  FROM z
 WHERE col1 = 'a';
DROP TABLE x;

Run it with sqlite the_database < the_script

like image 65
Benoit Avatar answered Jul 01 '26 20:07

Benoit