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

后端 未结 11 1840
野趣味
野趣味 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:37

    You can dump the content to a new table:

    CREATE TABLE failed_banks_id (id integer primary key autoincrement, name text, city text, state text, zip integer, acquired_by text, close_date date, updated_date date);
    
    INSERT INTO failed_banks_id(name, city, state, zip, acquired_by,close_date, updated_date)
    SELECT name, city, state, zip, acquired_by,close_date, updated_date
    FROM failed_banks;
    

    And rename the table:

    DROP TABLE failed_banks;
    ALTER TABLE failed_banks_id RENAME TO failed_banks;
    

提交回复
热议问题