Adding auto-incremented values to a table with one column

与世无争的帅哥 提交于 2019-12-07 18:15:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!