Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete Cascade

Author  Topic 

notmyrealname

98 Posts

Posted - 2009-06-02 : 15:47:38
Hi.

I have two tables. TableA and TableB. I have created a 'Many to One' relationship between the two tables. 'Many' in TableA and 'One' in TableB. I have set the foreign key to Delete Cascade. This works, but not in the direction i would like. If i delete a record from TableB it deletes all of the related records in TableA. What i am hoping to do is have the one record deleted from TableB only after the very last related record in TableA is deleted.

Can someone please tell me if this is possible? Also, is it possible to set things up so when a new record is added to TableA it is also automatically added to TableB?

Thanks for the help.

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-06-02 : 17:10:13
Well, that is kind of back-asswards cascading, and is not supported.
Normally the records in the Many table are deleted when the record in the One table is deleted.
I don't see any way around this except to write it in a trigger on your Many table.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

notmyrealname

98 Posts

Posted - 2009-06-03 : 09:58:30
Well i'm just a bass-ackwards kind of guy!

Thought i'd ask. I'll use triggers.

Thanks.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-06-03 : 12:45:51
problem No. welcome Your.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page
   

- Advertisement -