Android Sqlite table column foreign keys? -
i creating simple sqlite db android project. has been long time since have written msql commands, let alone sqlite.
to keep question simple, lets have 2 tables. 1 table dogs
, owners
.
in dogs
there column hold owner's _id
primary key other table.
i can't life of me remember how in sqlite or if can.
i creating dog table string :
private static final string create_table_dogs = "create table" + table_dogs + "(" + column_id + " integer primary key autoincrement, " + column_name + " text not null, " + column_owner + " integer );";
sqlite not have foreign keys enabled default. you'll need execute pragma foreign_keys=on;
every time before using database.
to create actual foreign key relation, add column dogs table this: foreign key(owners_id) references owners(_id)
. should define rules constraint violations.
for more information on sqlite foreign keys, check out https://www.sqlite.org/foreignkeys.html
Comments
Post a Comment