Can I alter a column in an sqlite table to AUTOINCREMENT after creation?

后端 未结 11 1836
野趣味
野趣味 2020-12-13 13:08

Can I make a field AUTOINCREMENT after made a table? For example, if you create a table like this:

create table person(id integer primary key, n         


        
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 13:55

    From the SQLite Faq

    Short answer: A column declared INTEGER PRIMARY KEY will autoincrement

    So when you create the table, declare the column as INTEGER PRIMARY KEY and the column will autoincrement with each new insert.

    Or you use the SQL statment ALTER to change the column type to an INTEGER PRIMARY KEY after the fact, but if your creating the tables yourself, it's best to do it in the initial creation statement.

提交回复
热议问题