Referential Integrity

I've made some tables which I've defined correct referential integrities for. I've chosen Cascade to be able to delete an entire branch from the hierarchy, meaning if I delete the parent, all its children are also deleted.

This is where it gets problematic. If I try to dlete a parent with Delphi or in Database Desktop, i get the error message "Master has detail records. Cannot delete or modify". I've tried changing the Delete property for this in the Database Explorer, but get an error message saying something like "Cannot edit Delete operation".

How can this be done?

regards,

johan
LVL 1
sagerydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dotanCommented:
I don't think that setting the referential integrities on a table gives you the ability to do this kind of thing.
You should delete the records starting from the chiled table and work your way up to the master table.
0
sagerydAuthor Commented:
Then why is there an option for Cascaded Deletion in the Database Explorer?
0
sagerydAuthor Commented:
Well dotan, if Cascaded Deletion doesn't work, what's the easiest way of deleting the child records from the child table when deleting the master record?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

aacrgCommented:
With which database are you working??
0
kretzschmarCommented:
hi sageryd,

you can do it with a query in the beforedelete event of your mastertable like

delete from childtable where MasterIdInChildTable = MasterIdInMasterTable

in code after preparing the sql-string do

query1.execute;
mastertable.Refresh;

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sagerydAuthor Commented:
aacrq: Paradox.


meikl:
That's exactly what I've been trying to do, but I can't get my code to work properly, could you give an example?

johan
0
aacrgCommented:
I guess there are no such things like cascaded constraints...
0
sagerydAuthor Commented:
ok. But it would have been nice without having to make additional queries for deleting child records though!
0
kretzschmarCommented:
ok, another way

you've a detailtable and a mastertable linked together in a master-detail relationship, now do as follows:

procedure TForm1.MasterTableBeforeDelete(DataSet: TDataSet);
begin
  while Not(DetailTable.Eof) do
    DetailTable.Delete;
end;

meikl
0
kretzschmarCommented:
hello?
0
sagerydAuthor Commented:
I didn't mean that I don't want to use them queries, because they're really good and fast. Well. During these two days I've been running Delphi like mad, trying to get my program to work properly. And now, there are only a few things left to fix!

The biggest problem at the moment is getting that damn BDE to understand that I only have seven fields, as it brings up errors saying that all fields aren't entered! But that I guess I'll have to try and fix that myself!

Thanx anyway meikl!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.