I'm trying to alter an SQLite table defined as follows:
String CREATE_TABLE="CREATE TABLE IF NOT EXISTS " + tab_NAME + " ("
+ row_ID + " INTEGER PRIMARY KEY , "
+ row_NAME + " TEXT, "
+ row_EMAIL + " TEXT, "
+ row_WEBSITE + " TEXT, "
+ row_TELEPHONE1 + " TEXT, "
+ row_TELEPHONE2 + " TEXT, "
+ row_TELEPHONE3 + " TEXT, "
+ row_TELEPHONE4 + " TEXT, "
+ row_TELEPHONE5 + " TEXT);";
db_name.execSQL(CREATE_TABLE);
String newTab="CREATE TABLE IF NOT EXISTS temp ("
+ row_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
+ row_NAME + " TEXT, "
+ row_EMAIL + " TEXT, "
+ row_WEBSITE + " TEXT, "
+ row_TELEPHONE1 + " TEXT, "
+ row_TELEPHONE2 + " TEXT, "
+ row_TELEPHONE3 + " TEXT, "
+ row_TELEPHONE4 + " TEXT, "
+ row_TELEPHONE5 + " TEXT);";
db_name.execSQL(newTab);
And here is the auto_increment alter statement:
String alter="ALTER TABLE temp AUTO_INCREMENT=1;";
ourDatabase.execSQL(alter);
I got an error saying (1) near AUTO_INCREMENT: syntax error
what's wrong?? any help??
In SQLite a column declared INTEGER PRIMARY KEY will autoincrement by itself. Remove the AUTOINCREMENT keyword and then try.
Check the SQLite FAQ
In sqlite
setting column as PRIMARY KEY
is an AUTOINCREMENT
. So there is no need of specifying explicitly column as AUTOINCREMENT
. Check this link for your reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With