SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help setting cascade on delete


Need help setting cascade on delete

Author
Message
junk.mail291276
junk.mail291276
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2143 Visits: 120
Hello,

I have a hierarchy of tables in my database. They look like this:

--Reports
----ReportMetrics
----ReportTopN
----ReportComments

That is, a one-to-many relation exists between reports and ReportMetrics, ReportTopN, and ReportComments. Each of the three child tables have foreign key references to a particular report.

I'm wondering how to set cascading on deletes.

I know that I can set the delete rule on foreign keys to Cascade in SSMS. I did it like so for the Report foreign key in ReportComments:



I did the same for the other two foreign keys. Then I tried to delete a report and it told me I couldn't because of a foreign key constraint. Then I opened the Foreign Key Relationships dialog box again and found that the delete rule had been set back to No Action. So it seems I can't set the delete rule to Cascade.

How does one set cascading on delete in SQL?
sgmunson
sgmunson
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89989 Visits: 6932
See the details here:

https://stackoverflow.com/questions/6260688/how-do-i-use-cascade-delete-with-sql-server

Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
junk.mail291276
junk.mail291276
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2143 Visits: 120
sgmunson - Thursday, March 8, 2018 9:10 AM

Excellent! That link has the answer I was looking for. Thanks!

sgmunson
sgmunson
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89989 Visits: 6932
junk.mail291276 - Thursday, March 8, 2018 2:55 PM
sgmunson - Thursday, March 8, 2018 9:10 AM

Excellent! That link has the answer I was looking for. Thanks!

Glad I could help.


Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search