Reputation: 423
How to crate a now row without knowing the any of the columns of the table and using default values therefore?
In sqlite3 I simply do:
sqlite> CREATE TABLE t ("id" INTEGER PRIMARY KEY, "text" TEXT DEFAULT "hello world");
sqlite> INSERT INTO t DEFAULT VALUES;
sqlite> SELECT * FROM t;
1|hello world
But in sqlite2.8.17 I get:
sqlite> INSERT INTO t DEFAULT VALUES;
SQL error near 'DEFAULT': Syntax error.
Is there a way to do this right in sqlite2 or do I need to give the values manually in the insert statement?
Upvotes: 1
Views: 2535
Reputation: 180030
You have to specify at least one value; all the others will then get their default values.
The rowid
automatically gets a value when you specify NULL
, so you can use that one:
INSERT INTO t(id) VALUES(NULL);
Upvotes: 5