SQLite foreign key? -
i have 2 tables: a
, b
. a
has foreign key b
, b
has foreign key a
. cannot make foreign key a
b
, because a
created before b
.
how can solve when sqlite doesn't support alter table
?
this sample database:
create table a( a_id integer primary key, b_id integer, a_description text, foreign key (b_id) references b(b_id) ) create table b( b_id integer primary key, a_id integer, b_description text, foreign key (a_id) references a(a_id) )
you have syntax error: there comma missing before foreign key
in table b
.
otherwise, schema correct. (sqlite interpret references
clauses when needed, there no problem creating reference table not yet exist.)
please note inserting records problematic, unless insert records null
values first , update them later when referenced record exists. might better idea create deferred foreign key constraints.
Comments
Post a Comment