sqlite3 - SQLite - Foreign key referencing rowid alias. Legal or not? -
in sqlite documentation says:
the parent key of foreign key constraint not allowed use rowid. parent key must used named columns only.
the parent key must named column or columns in parent table, not rowid.
but apply alias of rowid? example in sqlite if have integer primary key
column column alias of rowid:
with 1 exception noted below, if rowid table has primary key consists of single column , declared type of column "integer" in mixture of upper , lower case, column becomes alias rowid. such column referred "integer primary key".
(exception omitted; not relevant here)
there similar question here: sql - why referencing sqlite rowid cause foreign key mismatch? - stack overflow
if take example , modify use alias (my integer primary key column) appears work:
sqlite> create table foo(a integer primary key, name); sqlite> create table bar(foo_rowid references foo(a)); sqlite> insert foo values( null, "baz" ); sqlite> select * foo; name ---------- ---------- 1 baz sqlite> insert bar (foo_rowid) values(1); sqlite> select * bar; foo_rowid ---------- 1 sqlite>
but legal reference alias of rowid? thanks.
if internal rowid not named column, might not keep same values after vacuum, break foreign key references.
if rowid named, guaranteed keep values. using integer primary key parent of foreign key allowed, , common.
Comments
Post a Comment