I was wondering if there is a nice IF NOT EXISTS for checking columns and indexes in SQLite, or do I need to bring back the entire database schema and validate against that?
SELECT INSTR(sql, '<column_name>') FROM sqlite_master WHERE type='table' AND name='<table_name>'; Returns 0 (zero) if column <column_name> does not exists in the table <table_name> .
Stored procedures aren't really needed for Sqlite, since the program you write around Sqlite can certainly implement any 'stored' procedures itself. But beyond that you can certainly implement user functions which provide stored procedure results; but that's not a thing other databases can do.
SQLite does not support adding multiple columns to a table using a single statement. To add multiple columns to a table, you must execute multiple ALTER TABLE ADD COLUMN statements.
Syntax. The syntax to ADD A COLUMN in a table in SQLite (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition; table_name.
There is a system catalog table called sqlite_master that you can use to check index (or other) names:
SELECT name FROM sqlite_master WHERE type='index' ORDER BY name;
You can use a pragma to get the indexed columns:
PRAGMA index_info(index-name);
And this one to get the column names for a table:
PRAGMA table_info(table-name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With