0

Mycode

    final String createtabBook="CREATE TABLE IF NOT EXISTS BookMark(lid INTEGER AUTOINCREMENT,  bookdir TEXT , lastaddress TEXT,addresname TEXT PRIMARY KEY(bookdir,lastaddress));";
    db.execSQL(createtabBook);

Logcat:

03-05 18:29:31.708: I/System.out(17160): android.database.sqlite.SQLiteException: near "AUTOINCREMENT": syntax error: , while compiling: CREATE TABLE IF NOT EXISTS BookMark(lid INTEGER AUTOINCREMENT,  bookpath TEXT , lastchapter TEXT, PRIMARY KEY(bookpath,lastchapter));

i just want to create a table with composite primary key so that it is a combination of bookdir and lastaddress, also i want to make the lid as auto increment.

Mukund
  • 1,107
  • 2
  • 18
  • 40
  • possible duplicate of [SQLite multi-Primary Key on a Table, one of them is Auto Increment](http://stackoverflow.com/questions/6154730/sqlite-multi-primary-key-on-a-table-one-of-them-is-auto-increment) – laalto Mar 05 '14 at 13:15

1 Answers1

4

To get the value of any column autoincrement you need to write it or declare it as primary key.

In SQLite a column declared INTEGER PRIMARY KEY will autoincrement.

EDITED:

As you can not define more than one PRIMARY KEY in a table you have to make the bookdir,lastaddress columns as UNIQUE and define the lid columns as PRIMARY KEY as below:

Try out as below:

 final String createtabBook="CREATE TABLE IF NOT EXISTS BookMark(lid INTEGER PRIMARY KEY AUTOINCREMENT,  
  bookdir TEXT , lastaddress TEXT,addresname TEXT, UNIQUE(bookdir,lastaddress));";

Also add "," after the column addresname TEXT, in your query.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • @laalto Now what is the problem i did change. – GrIsHu Mar 05 '14 at 13:22
  • Consider using a tool such as sqlite3 to check your syntax. Also, there is the keyword `autoincrement` and it has specific place in syntax. – laalto Mar 05 '14 at 13:27
  • 3
    @laalto I did changed my answer now its fair revoke your vote. I have checked its fine now. – GrIsHu Mar 05 '14 at 13:27