Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Delete parent record
17 posts, Page 2 of 2
««
1
2
Delete parent record
Rate Topic
Display Mode
Topic Options
Author
Message
Jack Corbett
Jack Corbett
Posted Thursday, May 27, 2010 9:17 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 1:41 PM
Points: 10,613,
Visits: 11,952
I've never used Cascading updates or deletes. I think that there is a reason for the FK and that I shouldn't just blindly update or delete child information. If there is a business reason for deleting the parent then there should be business rules enforced in the application for it. I don't think I should be able to do the delete outside the application in that case.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #929077
Paul White
Paul White
Posted Thursday, May 27, 2010 9:19 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 2:43 PM
Points: 10,990,
Visits: 10,576
Jack Corbett (5/27/2010)
I've never used Cascading updates or deletes. I think that there is a reason for the FK and that I shouldn't just blindly update or delete child information. If there is a business reason for deleting the parent then there should be business rules enforced in the application for it. I don't think I should be able to do the delete outside the application in that case.
I tend to agree, but this was an interview question to check technical knowledge and/or lateral thinking.
I've only ever used SET NULL, and both times were a work around in a 3rd party system.
Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #929080
Jack Corbett
Jack Corbett
Posted Thursday, May 27, 2010 9:26 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 1:41 PM
Points: 10,613,
Visits: 11,952
Paul White NZ (5/27/2010)
Jack Corbett (5/27/2010)
I've never used Cascading updates or deletes. I think that there is a reason for the FK and that I shouldn't just blindly update or delete child information. If there is a business reason for deleting the parent then there should be business rules enforced in the application for it. I don't think I should be able to do the delete outside the application in that case.
I tend to agree, but this was an interview question to check technical knowledge and/or lateral thinking.
I've only ever used SET NULL, and both times were a work around in a 3rd party system.
I should have quoted Steve's post asking if anyone's used it.
Yes, for an interview answer cascading deletes with SET NULL would be the best answer. Even with this I'd rather enforce it in a stored procedure or business layer, if not using stored procedures. Of course both assume that the column in the child is nullable.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #929088
Paul White
Paul White
Posted Thursday, May 27, 2010 9:30 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 2:43 PM
Points: 10,990,
Visits: 10,576
Jack Corbett (5/27/2010)
I should have quoted Steve's post asking if anyone's used it.
Oh, right, gotcha
Yes, for an interview answer cascading deletes with SET NULL would be the best answer. Even with this I'd rather enforce it in a stored procedure or business layer, if not using stored procedures. Of course both assume that the column in the child is nullable.
It also assumes that NULL and the DEFAULT value are valid parent keys...this usually prompts a long discussion about whether RI is violated by allowing this behaviour. My view is that if the FK relationship stays valid, there's RI. Not everyone agrees with me.
Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #929093
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Thursday, May 27, 2010 9:35 AM
SSC-Dedicated
Group: Administrators
Last Login: Yesterday @ 3:19 PM
Points: 31,526,
Visits: 13,863
My view is the PKs, FKs, are based on business rules. You can't define an OrderItem to be definitely linked to an Order without a business rule. So if the business rule allows defaults or NULLs for the FK, then it doesn't violate RI.
However, that somehow assumes that the person performing the update really understands the business rules, and has correctly explained this to the business and gotten agreement. That's where I'd be concerned.
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #929096
ZenDada
ZenDada
Posted Thursday, May 27, 2010 10:06 AM
SSC-Addicted
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 1:50 PM
Points: 434,
Visits: 270
Here's what we do. My tables have an is_delete bit on them. When a record's is_delete bit is set on or off, a trigger cascades the is_delete bit to any dependent records in other tables. Sadly, the cascading feature that is available does not support this, so a trigger is needed.
But that is our solution. I record these cascades in an audit trail table so I can follow the chain and report on who did it and which dependent tables were affected.
ZenDada
Post #929113
ShekharNaidu
ShekharNaidu
Posted Friday, May 28, 2010 12:45 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, November 08, 2010 10:45 PM
Points: 122,
Visits: 70
thanx to all of you... for spending ur time... helping me out...
Thanks ,
Shekhar
Post #929480
« Prev Topic
|
Next Topic »
17 posts, Page 2 of 2
««
1
2
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.