Subject | very basic questions about FK |
---|---|
Author | Sergio H. Gonzalez |
Post date | 2009-10-14T14:05:05Z |
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.
Thanks!
-sergio
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.
Thanks!
-sergio