问题
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.
回答1:
Try the following:
INSERT INTO YOUR_TABLE(YOUR_ID) VALUES (NULL);
回答2:
Try this
INSERT INTO dbo.Table DEFAULT VALUES
See this answer: Previous answer
来源:https://stackoverflow.com/questions/7878369/adding-auto-incremented-values-to-a-table-with-one-column