sqlite - Is it possible to structure a SQL query to automatically create a table if it doesn't already exist? -


I am a full SQL novice, and I am trying to complete the following (phony code) with a single query : (If a table named "config_data" does not exist) create a table called {{config_data}} if (there is no line of "config_data") {Add a line to "config_data" in some default data} "config_data" Return all the rows

How do I go about this? Can this be done with a question? I'm using SQLite3, if it helps.

So far, I know how to create a table, and enter data in it:

  create table config_data (main text, value text); Enter the values ​​in the Config_data ("Key_1", "Value_1"); Insert in config_data values ​​("key_2", "value_2");  

And also how to delete all the rows:

  Select * from config_data;  

This is a fancy combination that gives me the :

To create a table if it is not already present, you can use it:

  does not create, config_data does not exist (key text tap, value text , Contract key_unique UNIQUE (key))  

For your second part, you can use () to insert a value, assume that you have a unique obstacle, Which is twice the price Inserting the target would otherwise be a violation (for example, your key may be an integral bar on the column):

  INSERT or config_data values IGNORE  
("key_1", "def_value_1")

Comments