Subject | Re: [IBO] Re: Masterlinks demo - does not work ? |
---|---|
Author | Helen Borrie |
Post date | 2000-12-28T21:01:52Z |
At 08:02 PM 28-12-00 +0000, you wrote:
referenced details exist. If you want cascading deletes you must add them
to the constraint; or write a Before Delete trigger for the master that
deletes the details first.
integrity works. There is quite a bit about it in the IB 6 beta manuals,
albeit spread out in several different places.
to understand how foreign keys work - it is structurally quite different
from the hierarchical primary key structure with which you form referential
relationships in Paradox.
don't. The typical way to form a master-detail relationship is to have a
column in the detail table that holds the primary key of the master. To
get uniqueness in the detail records, use a surrogate primary key for that
table.
not have worked.
column of the master must be. Stop thinking about "secondary indexes" -
that concept is peculiar to Paradox and has no meaning in a RDBMS. Indexes
are indexes, keys are keys. It happens that, when you apply a PK
constraint to a column or composite, IB automatically creates a unique
index for it; and when you apply a FK constraint to a column or composite,
IB automatically creates a non-unique index for it, PROVIDED no rows
contain NULL. It may be the presence of NULL in the FK column that is
preventing you from applying the FK constraint.
To repeat - creating an index does not create a key. Key constraints must
be applied specifically. Remove any indexes on the keys before you do it,
though, as you will get duplicate indexes otherwise, and these cause the
optimizer to work incorrectly.
recommend Graeme Simsion's book "Data Modeling Essentials: Analysis,
Design and Innovation".
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________
> > > When I delete entry from master table want all detail recordsThe foreign key constraint **constrains** you from deleting a master whilst
>also to
> > > be deleted. As far as I can tell, masterlinks demo should do this
> > > but when I try to delete a record from the master table I get an
> > > error about Violation of Foreign Key Constraints.
referenced details exist. If you want cascading deletes you must add them
to the constraint; or write a Before Delete trigger for the master that
deletes the details first.
> > >Any good book on database design will explain how cascading referential
> > > Can someone point me in the right direction to learn how to
> > > accomplish this.
> >
integrity works. There is quite a bit about it in the IB 6 beta manuals,
albeit spread out in several different places.
> > Change the referential integrity to cascade the delete instead ofThere is a vast difference between Paradox and InterBase. You really need
> > restricting it. Also, you could use a trigger that would delete the
>child
> > records when the master record is being deleted.
>
>Being new to Interbase and IBO, I may simply not understand but I can
>find no way to accomplish what I need.
to understand how foreign keys work - it is structurally quite different
from the hierarchical primary key structure with which you form referential
relationships in Paradox.
>Initially my application ran under the BDE using Paradox tables. IDon't confuse keys and indexes. Keys form relationships, indexes
>had a master table, Employee. I also had a PayControl table. The
>PayControl table had a secondary (non unique) index by EmployeeNumber
>since each employee could have any number of pay control records.
don't. The typical way to form a master-detail relationship is to have a
column in the detail table that holds the primary key of the master. To
get uniqueness in the detail records, use a surrogate primary key for that
table.
>When I deleted the master (Employee) record, since the tables wereThis is what the cascading delete (or Before Delete trigger) does for you.
>linked master/detail, all I had to do was
>With PayControlTable Do
>Begin
> First;
> While Not Eof Do
> Delete;
>End;
>and all pay control records for the employee were deleted.
>I then converted the application to Interbase using IBX. With noThat's a puzzle - if you had a foreign key defined at that time, it should
>change to the logic, all worked fine.
not have worked.
>I have now converted to IBO but since I can find no where to have IBOThe foreign key column does not have to be unique; but the primary key
>use a secondary index, the logic no longer works. I get a multiple
>records deleted error.
>
>I have tried to use Foreign keys to set up referential integrity but,
>If I userstand correctly, the keys must be unique. Since the
>PayControl table contains non unique keys, I can't see how to make
>this work.
column of the master must be. Stop thinking about "secondary indexes" -
that concept is peculiar to Paradox and has no meaning in a RDBMS. Indexes
are indexes, keys are keys. It happens that, when you apply a PK
constraint to a column or composite, IB automatically creates a unique
index for it; and when you apply a FK constraint to a column or composite,
IB automatically creates a non-unique index for it, PROVIDED no rows
contain NULL. It may be the presence of NULL in the FK column that is
preventing you from applying the FK constraint.
To repeat - creating an index does not create a key. Key constraints must
be applied specifically. Remove any indexes on the keys before you do it,
though, as you will get duplicate indexes otherwise, and these cause the
optimizer to work incorrectly.
>Can you assist in a more detailed explanation as to how to handle aIt's not an IBO matter, it's a fundamental database design issue. I
>delete situation like mine.
recommend Graeme Simsion's book "Data Modeling Essentials: Analysis,
Design and Innovation".
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________