Create table in SQLite only if it doesn't exist already

user461112 picture user461112 · Nov 4, 2010 · Viewed 209.3k times · Source

I want to create a table in a SQLite database only if doesn't exist already. Is there any way to do this? I don't want to drop the table if it exists, only create it if it doesn't.

Answer

David Wolever picture David Wolever · Nov 4, 2010

From http://www.sqlite.org/lang_createtable.html:

CREATE TABLE IF NOT EXISTS some_table (id INTEGER PRIMARY KEY AUTOINCREMENT, ...);