Subject | Re: [ib-support] newbie questions |
---|---|
Author | Helen Borrie |
Post date | 2002-01-21T11:19:24Z |
At 11:50 AM 21-01-02 +0100, you wrote:
Or triggers to enforce the uniqueness of the N_MOV | MOV_YEAR combination? If every incoming date has to be tested to ascertain whether it is unique for year, you would need a trigger to extract YEAR from the date in order to test it.
--hb
All for Open and Open for All
Firebird Open SQL Database ยท http://firebirdsql.org
_______________________________________________________
>>I strongly recommend an atomic primary key (generated) and triggers toGenerated atomic primary key? Establish a NUMERIC(18,0) primary key and populate it by trigger (or otherwise) from a generator. Place a UNIQUE constraint (or a UNIQUE index, if you need it) on the composite column structure that has been surrogated. Any foreign keys will refer to the primary key, not the columns in the index. In InterBase, it's wise to create foreign keys *before* you start adding unique indexes elsewhere in the table.
>enforce the uniqueness of the N_MOV | MOV_YEAR combination.
>
>could you please expand on this ?
Or triggers to enforce the uniqueness of the N_MOV | MOV_YEAR combination? If every incoming date has to be tested to ascertain whether it is unique for year, you would need a trigger to extract YEAR from the date in order to test it.
>From what you said, I find much easier to add a MOV_YEAR field to the tableIf your solution is calculate Year from DecodeDate() in Delphi and pass it directly, all that expression stuff is avoided. The unique constraint on the movement/year combination will catch an exception without having to worry about the actual date.
>and fill it from my D3 program.
>>It is a Very Bad Idea to involve dates in keys, too.No, the world out there doesn't require you to involve dates in keys. The world out there requires movement numbers to be unique within year.
>
>not my idea.
>
>The world out there requires that.
>Every warehouse movement must be identified by a progressive number that isSo: but there is no law that says it has to be the primary key of a table. But there are rules of healthy practice in database design which include making keys atomic (independent or meaning as data).
>unique in the year it takes place.
--hb
All for Open and Open for All
Firebird Open SQL Database ยท http://firebirdsql.org
_______________________________________________________