Subject | Re: [firebird-support] Nullable foreign keys |
---|---|
Author | Paul Vinkenoog |
Post date | 2004-04-29T10:08:01Z |
Hi Christian,
You define the FKs as the same datatype, but nullable. For instance:
create domain DID integer not null;
create domain DID_NULL integer;
create table Mutter (
id DID primary key
);
create table Kind (
id DID primary key,
mutti DID_NULL references Mutter( id )
);
Now each record in Kind can have the mutti field NULL, but if it's
non-NULL it *must* refer to an existing id in Mutter.
Greetings,
Paul Vinkenoog
> for me it is not only sub-optimal, but also unsatisfying, becauseYou define the PKs as a non-nullable datatype - like you already do.
> all of my FKs are linked to the PKs of other tables which must never
> be NULL.
> Any other idea how I can do this?
You define the FKs as the same datatype, but nullable. For instance:
create domain DID integer not null;
create domain DID_NULL integer;
create table Mutter (
id DID primary key
);
create table Kind (
id DID primary key,
mutti DID_NULL references Mutter( id )
);
Now each record in Kind can have the mutti field NULL, but if it's
non-NULL it *must* refer to an existing id in Mutter.
Greetings,
Paul Vinkenoog