user2085965
user2085965

Reputation: 403

How to set foreign key in android sqlite

How to set the primary key of CREATE_PARENT_M_LIST table as foreign key to CREATE_CHILD_M_LIST

Here are my queries.

// My parent table.
public static String CREATE_PARENT_M_LIST = "create table if not exists "+
DATABASE_TABLE1 + " ( p_id integer primary key autoincrement, "
        + "table_name text);"; 

// my child table.
public static String CREATE_CHILD_M_LIST = "create table if not exists "
        + DATABASE_TABLE2 + " ( id integer primary key autoincrement, "
        + " symbol text," + " f_id integer," 
        + " foregin key(f_id) references " + DATABASE_TABLE1 + "(p_id));";

I am getting syntax error near f_id column

Thanks in advance.

Upvotes: 1

Views: 79

Answers (1)

nano_nano
nano_nano

Reputation: 12524

becouse you got a spelling error:

foregin key(f_id) references 

change it to

foreign key(f_id) references 

Upvotes: 1

Related Questions