android sqlite CREATE TABLE IF NOT EXISTS

前端 未结 2 1423
不知归路
不知归路 2021-02-19 02:26

Having a little problem with creating new tables. When I use the CREATE TABLE command my new tables form as they should, but when I exit the activity the app crashes and I get a

2条回答
  •  萌比男神i
    2021-02-19 02:56

    That's how it's supposed to work. CREATE TABLE will throw an exception if the table already exists. CREATE TABLE IF NOT EXISTS will create the table if it doesn't exist, or ignore the command if it does. If you want it to delete the old table, use DELETE TABLE IF EXISTS before CREATE TABLE. If you want to change the schema, use ALTER TABLE, not CREATE TABLE.

提交回复
热议问题