On Tue, Dec 13, 2016 at 8:07 PM, David Raymond <david.raym...@tomtom.com>
wrote:

> sqlite> create table parentTable
>    ...> (
>    ...>   id integer primary key,
>    ...>   a int not null,
>    ...>   b int not null,
>    ...>   otherStuff,
>    ...>   unique (a, b)
>    ...> );
>
> sqlite> create table childTable
>    ...> (
>    ...>   id integer primary key,
>    ...>   a int, --nullable
>    ...>   b int, --nullable
>    ...>   otherStuff,
>    ...>   foreign key (a, b) references parentTable (a, b)
>    ...> );
>

But why would you do that?

If you have unique(a, b), that implies it's your natural key (NK),
and id is "just" the surrogate key (SK). And the whole point of
a surrogate key is to have lighter-weight (to store and index)
and faster to match against foreigns keys (FKs). Otherwise you
might as well set (a, b) as your PK, and not have an SK at all. --DD
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to