Subject Re: [firebird-support] very basic questions about FK
Author Kjell Rilbe
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?

I would do it the way you do, with -999 or rather -1. Or perhaps even an
ordinary positive number. Why not? It seems to me that your "free item"
is a kind of article, it just has some special properties, that should
probably be flagged in the articles table, e.g. "Special, free-text" = 'Y'.

> (*)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)

Why wouldn't that be good? As far as I know, that's the normal way to do
this.

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