all groups > sql server msde > january 2006 >
You're in the

sql server msde

group:

SQL Logic


SQL Logic Robert Bravery
1/27/2006 12:00:00 AM
sql server msde: HI all,

I need help on some SQL logic.
I have a two tables related. The parent has cascading deletes set. Which
obviously means when deleting a parent all children are deleted as well.
Which is what I want.
Also the user has opertuninty to delete indivisual child records, With one
exceptions. He cannot delete the child record if the is only one record
left. He either has to leave it as it it, or add a second child then delete
his original choice, or delete the child along with the parent.
I had put in a delete trigger to do this, but because my logic is flawed,
when, correctly deleting the parent, the delete fails because my trigger
wont allow the child record, being the last one to be deleted.
Does anyone have any ideas as to how I can achieve this buisness rule

THanks
Robert

RE: SQL Logic Sreejith G
2/3/2006 3:39:22 AM
Hi,

Just do it simple, like inside the tigger go for an "if exists" check

i.e,

inside trigger,

If not exists (In parent table )
DELETE from child...

Thanks,
Sree

[quoted text, click to view]
AddThis Social Bookmark Button