SQLite add Primary Key

前端 未结 11 2435
你的背包
你的背包 2020-11-28 06:07

I created a table in Sqlite by using the CREATE TABLE AS syntax to create a table based on a SELECT statement. Now this table has no primary key b

11条回答
  •  遥遥无期
    2020-11-28 06:45

    I had the same problem and the best solution I found is to first create the table defining primary key and then to use insert into statement.

    CREATE TABLE mytable (
    field1 INTEGER PRIMARY KEY,
    field2 TEXT
    );
    
    INSERT INTO mytable 
    SELECT field1, field2 
    FROM anothertable;
    

提交回复
热议问题