Reputation: 15
Hey i made a whole app without adding an autoincrement column but now i need this column to specify the max id so i created my database in my mainactivity like this.How can i modify this to add the autoincrement _id column ?
db = getActivity().openOrCreateDatabase("testDB2", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS test2(mac VARCHAR,mdp VARCHAR,obj VARCHAR);");
I don't want to create a seonc java classs only for the database because i did all the code like this.
Upvotes: 1
Views: 55
Reputation: 12147
You can't alter the sqlite
table to add _id
column as primary key after table created.
What you should do is creating a new table, then copy the old data to the new table.
See the faq from sqlite.org
Upvotes: 1
Reputation: 60
db.execSQL("CREATE TABLE IF NOT EXISTS test2(autoincrement_id INTERGER PRIMARY KEY AUTOINCREMENT,mac VARCHAR,mdp VARCHAR,obj VARCHAR);"); only primary key can be autoincrement
Upvotes: 0