user1011201
user1011201

Reputation: 83

Adding auto-incremented values to a table with one column

I need to create a table that basically keeps a list of indices only. Therefore I've created a table with just one, auto-incremented column called 'id'. However, I can't seem to implicitly add auto-incremented values to this table.

I know that usually when you have such a column in a table (with more than just this column) you can do:

INSERT INTO TABLE (col1, col2 ...) VALUES (val1, val2 ...)

And if you don't specify the auto-incremented column, it would automatically get a value. However, things like:

INSERT INTO TABLE () VALUES () INSERT INTO TABLE INSERT INTO TABLE ()

etc. all produce an error on my single-columned table. Can anyone offer a solution? Thanks.

p.s. I'm using Sqlite, in case it matters.

Upvotes: 4

Views: 2203

Answers (2)

Sparky
Sparky

Reputation: 15125

Try this

INSERT INTO dbo.Table DEFAULT VALUES 

See this answer: Previous answer

Upvotes: 5

Ernesto Campohermoso
Ernesto Campohermoso

Reputation: 7391

Try the following:

 INSERT INTO YOUR_TABLE(YOUR_ID) VALUES (NULL);

Upvotes: 2

Related Questions