I need my PHP app to be able to create an SQLite table but only if it doesn't already exist. How should I go about it?
The IF NOT EXISTS clause prevents you from an error of creating a new database that already exists in the database server. You cannot have 2 databases with the same name in a MySQL database server.
SQLite DELETE query is used to remove existing records from a specified table. You can use the WHERE clause with DELETE queries to delete the selected rows. You have to write a table name after the DELETE FROM clause, from which you want to delete records.
When you try to create a table with an already existing table name, you will receive an error message, and no table will be modified or created.
You can use:
CREATE TABLE IF NOT EXISTS <name> ( /* definition */ )
Which is supported by SQLite (http://www.sqlite.org/syntaxdiagrams.html#create-table-stmt)
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