Subject Re: [firebird-support] very basic questions about FK
Author Kjell Rilbe
Sergio H. Gonzalez wrote:

> Hello, I'd like to know if this is a "good practice"... In some tables I
> have a
> some IDs that could be "with no value" but in most of the cases they
> have values
> pointing to other tables. I still define the IDs as not null and create
> foreign
> keys and use negative values (-999, for instance) and create a "system
> record"
> (id = -999) which means "no value" and have triggers that would prevent
> any user
> to delete a record with an ID < 0, raising an exeception like "this is a
> system
> record, can't be deleted"
>
> Is this ok? or is better, in that cases, not to use a foreign key and
> let the
> field be null ?
>
> I know this may be a silly question, but I'd like to know how
> experienced people
> handle these situations.

My immediate thought is that you should stick with null, but I'm sure
others have more insightful comments to make. I just think that as long
as you use null for what it actually means "unknown value", then you're
OK. In that case null in your case would mean "I don't know which master
record this detail record belongs to". If, on the other hand, your
business logic is more like "I know this detail record doesn't belong to
any master recpord and that is OK", then perhaps your approach is more
"to the point".

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64