1

Is this supported? I'm attempting to create a table but am getting a syntax error when compiling.

private static final String ROOM_CREATE =
        "create table room (_id integer primary key autoincrement, " +
        "facility integer not null, FORIEGN KEY (facility) REFERENCES facility(_id));";
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
bgrantdev
  • 1,622
  • 4
  • 17
  • 29
  • possible duplicate of [Foreign key constraints in Android using SQLite? on Delete cascade](http://stackoverflow.com/questions/2545558/foreign-key-constraints-in-android-using-sqlite-on-delete-cascade) – Ted Hopp Jan 12 '12 at 19:34
  • It is possible. Syntax error from compiling could be different one, can you post the error you are getting? – kosa Jan 12 '12 at 19:37
  • FORIEGN KEY...syntax error – Paranoid Android Jul 30 '13 at 10:44

4 Answers4

0

You can create foreign keys, but you have to enable enforcement in SQLite with

PRAGMA foreign_keys = ON;
P Varga
  • 19,174
  • 12
  • 70
  • 108
0

Typo in the SQL:

FORIEGN -> FOREIGN

sebastianf182
  • 9,844
  • 3
  • 34
  • 66
0

Some great answers, particularly @sfratini for spotting the typo in the FOREIGN keyword. Can I also recommend that you should troubleshoot your SQL statements by using a command line client, such as the "Precompiled Binaries For Windows" (see http://sqlite.org/download.html). That way, you can validate the CREATE TABLE and INSERT statements before you put them into your app.

Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
-1

The facility in facility(_id) must refers to table name. You are defining same name to column also. Please change table name and try again.

GrAnd
  • 10,141
  • 3
  • 31
  • 43
Ramesh 586
  • 67
  • 3