Nirav
Nirav

Reputation: 5760

Sqlite Query Error

I am using sqlite db in android.
In this I need to give Id as autoincrement and second 'Incoming_sms' field as primary key. but it shows me error as below:

detailMessage "near "AUTOINCREMENT": syntax error:  
CREATE TABLE TwoWayTable111 (
  ID INTEGER AUTOINCREMENT,  
  INCONMING_MSG TEXT PRIMARY KEY,  
  OUTGOING_MSG TEXT,  
  STATUS TEXT )" 

Why does this error occur? But when I give id as autoincrement and primary key, it works fine.

Upvotes: 0

Views: 126

Answers (1)

This is a FAQ. It works as designed. This statement returns a syntax error.

create table test (id integer autoincrement);

This one runs without error.

create table test (id integer primary key autoincrement);

You should be able to do this.

CREATE TABLE TwoWayTable111 (
    ID INTEGER PRIMARY KEY, 
    INCONMING_MSG TEXT NOT NULL UNIQUE, 
    OUTGOING_MSG TEXT, 
    STATUS TEXT );

Upvotes: 1

Related Questions