Subject | Key strucs, was Re: Error:Object is in use |
---|---|
Author | Helen Borrie |
Post date | 2001-02-23T23:24:36Z |
At 01:59 PM 23-02-01 +0100, you wrote:
If you have no need for an index on (ORDER_ID, ORDER_POS), don't create an index.
You said:
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________
>Helen Borrie wrote:I don't know yet. There will be some kind of mechanism for subscribing to the review panel (free) but I haven't worked out the details yet.
>
> > Not stupid, just time-consuming. :)) I'd better write a handbook....
>
>Is it possible to prepay for the book and get the pages which are done?
> > >They never see ORDER_ID. I use it so they can delete an order withoutNo - I mean it's very satisfactory that you made the Order_No independent of any keys. :))
> > >really deleting it, and they can use the deleted Order_No for a new order.
> > >They are so afraid of the tax office. They say, the tax office wants
> > >continuously numbers.
> >
> > That's cool, very satisfactory. :))
>
>The tax office ? :-))
>that case, I would want the stability of a unique surrogate PK. I don't like structures where humans are capable of bending keys.Don't create an index for Parts(ORDER_ID) !!!! The foreign key constraint will cause this index to be created automatically. If you duplicate it, you will create ambiguity for the optimizer and it won't choose either index, but Natural order instead.
>
>
>But it is possible that the user can change the ORDER_POS.
>And therefore I will change the structure.
>Yes, you convinced me. :-)
>
>But which model is better?
>
>CREATE TABLE PARTS
>(
> PARTS_ID D_PARTS_ID
> ORDER_ID D_ORDER_ID,
> ORDER_POS D_ORDER_POS,
> ORDER_POS_OLD D_ORDER_POS DEFAULT 0,
> DRAFT_NO D_DRAFT_NO NOT NULL,
> APPELLATION D_APPELLATION NOT NULL,
> AMOUNT_ORDERED INTEGER NOT NULL,
> .
> .
> .
> DELETED D_BOOLEAN,
> CONSTRAINT PK_PARTS_ID PRIMARY KEY (PARTS_ID),
> CONSTRAINT FK_PARTS_ORDER_ID FOREIGN KEY (ORDER_ID) REFERENCES
>ORDER (ORDER_ID)
> ON DELETE NO ACTION
> ON UPDATE CASCADE
>);
>CREATE UNIQUE INDEX UIDX_P_ORDER_ID_POS ON PARTS (ORDER_ID, ORDER_POS);
>CREATE INDEX IDX_P_DRAFT_NO ON PARTS(DRAFT_NO);
>
>Or
>
>
>CREATE TABLE PARTS
>(
> PARTS_ID D_PARTS_ID
> ORDER_ID D_ORDER_ID,
> ORDER_POS D_ORDER_POS,
> ORDER_POS_OLD D_ORDER_POS DEFAULT 0,
> DRAFT_NO D_DRAFT_NO NOT NULL,
> APPELLATION D_APPELLATION NOT NULL,
> AMOUNT_ORDERED INTEGER NOT NULL,
> .
> .
> .
> DELETED D_BOOLEAN,
> CONSTRAINT PK_PARTS_ID PRIMARY KEY (PARTS_ID),
> CONSTRAINT FK_PARTS_ORDER_ID FOREIGN KEY (ORDER_ID) REFERENCES
>ORDER (ORDER_ID)
> ON DELETE NO ACTION
> ON UPDATE CASCADE,
> CONSTRAINT UK_ORDER_ID_POS UNIQUE (ORDER_ID, ORDER_POS)
>);
>CREATE INDEX IDX_P_DRAFT_NO ON PARTS(DRAFT_NO);
>CREATE INDEX IDX_P_ORDER_ID ON PARTS(ORDER_ID);
>
>Or something else?
If you have no need for an index on (ORDER_ID, ORDER_POS), don't create an index.
You said:
> I have two tables (Work and ForeignFirm) who have a foreign keyWell, change that, so that the foreign key refers to PARTS_ID. It is the **row** that the relationship needs to be formed to, not the **meaningful data**. There will be no need for the on update cascade then.
> (ORDER_ID, ORDER_POS) to Parts, with ON UPDATE CASCADE.
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________