4

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.

  • possible duplicate of [How to insert into a table with just one IDENTITY column (SQL Express)](http://stackoverflow.com/questions/1362148/how-to-insert-into-a-table-with-just-one-identity-column-sql-express) – MatBailie Oct 24 '11 at 15:56

2 Answers2

5

Try this

INSERT INTO dbo.Table DEFAULT VALUES 

See this answer: Previous answer

Community
  • 1
  • 1
Sparky
  • 14,967
  • 2
  • 31
  • 45
  • At 3000 rep you can vote to close rather than referencing another question as your answer. – MatBailie Oct 24 '11 at 15:59
  • Thanks, I saw from your comment that it is better to refer to a previous answer as a comment. I'll do that from now on. – Sparky Oct 24 '11 at 16:44
2

Try the following:

 INSERT INTO YOUR_TABLE(YOUR_ID) VALUES (NULL);
Ernesto Campohermoso
  • 7,213
  • 1
  • 40
  • 51