Subject Re: [firebird-support] very basic questions about FK
Author Mark Rotteveel
Sergio H. Gonzalez wrote:
> Thanks guys for the quick answer!! I use the FK just to check data integruty.
> This is an example:
>
> When I do an invoice, most of the items of the invoices are a reference to the
> article's table (*) but some times the user can add a "free item" to the
> invoice. It means: a line in the invoice that is entered by the user wich don't
> point to an article. In that cases I set teh ID_article field to -999 and in the
> article's table I have a record: ID_Article = -999 / Description = 'Free Item'.
> That way I can use a FK to presererve data integrity. If I allow nulls in
> ID_Article I could check for data integrity whith triggers... so... what should
> I do?
>
> -s
>
> (*)I know that this is NOT very good, but I also copy the description of the
> article in the invoice detail table... the problem is that the description of an
> item may change and I don't want the invoice to change any of the descriptions)

What is a free item? I assume those 'free items' are specific products
that are actually delivered to those customers. If so why aren't there
specific records in your ARTICLE table to represent a specific free
item? Otherwise there is no way to link actually delivered items to the
invoice which can get you or the receiver of the goods in trouble
(depending on laws and regulations).

If you would change your model, most likely the question/problem you are
now having is solved.

Mark
--
Mark Rotteveel