Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Delete parent record Expand / Collapse
Author
Message
Posted Thursday, May 27, 2010 9:17 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:07 AM
Points: 11,157, Visits: 12,899
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
Posted Thursday, May 27, 2010 9:19 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:36 AM
Points: 11,192, Visits: 11,091
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
Posted Thursday, May 27, 2010 9:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:07 AM
Points: 11,157, Visits: 12,899
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
Posted Thursday, May 27, 2010 9:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:36 AM
Points: 11,192, Visits: 11,091
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
Posted Thursday, May 27, 2010 9:35 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 2:28 PM
Points: 33,062, Visits: 15,174
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
Posted Thursday, May 27, 2010 10:06 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:07 AM
Points: 434, Visits: 272
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
Posted Friday, May 28, 2010 12:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 8, 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 »

Add to briefcase ««12

Permissions Expand / Collapse