Reputation: 69
I have a table that is only a single column, INTEGER PRIMARY KEY.
As it's an autoincrement, How do I insert a value?
I've tried
INSERT INTO Rule DEFAULT VALUES;
which runs but doesn't actually insert anything. any other ideas?
Thanks!
Upvotes: 2
Views: 2086
Reputation: 180020
The following command creates a column named INTEGER with no type:
> CREATE TABLE wrong(INTEGER PRIMARY KEY);
> INSERT INTO wrong DEFAULT VALUES;
> INSERT INTO wrong DEFAULT VALUES;
> SELECT * FROM wrong;
INTEGER
----------
If you don't forget the column name, DEFAULT VALUES works just fine with an INTEGER PRIMARY KEY column:
> CREATE TABLE Rule(RuleID INTEGER PRIMARY KEY);
> INSERT INTO Rule DEFAULT VALUES;
> INSERT INTO Rule DEFAULT VALUES;
> SELECT * FROM Rule;
RuleID
----------
1
2
Upvotes: 3
Reputation: 152797
Insert a null
:
sqlite> create table a(a integer primary key autoincrement);
sqlite> insert into a values(null);
sqlite> insert into a values(null);
sqlite> select * from a;
1
2
Upvotes: 2