Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2009, 10:14 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default cascading delete with Store Procedure

Hi All !

I have a database table for products which contains data of all products with thir Category, Sub-Category, name etc up to the nth level.

Structure as follows:

Product ID | Product Name | ParentCategory ID
-------------------------------------------------------------------------
0001 | Top Product | NULL
0002 | Prod1 | 0001
0003 | Prod4 | 0001
0004 | Prod55 | 0003

Here with this table structure I want to use a Store Procedure where If I delete a particular product, then if that product is the parent of any other product that product will also be deleted simultaneously until no products remain in that heirarchy.


Can anyone provide me the Store Procedure code.

Thanks in advance
 
Old September 24th, 2009, 12:41 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

There is no readymade source code available for this.

You need to write a stored procedure which will loop recursively and delete all the products...

Please check the following link which will be helpful:

http://www.simple-talk.com/sql/t-sql...e-expressions/
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13233
http://forums.asp.net/t/1028727.aspx
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Store procedure help... RinoDM SQL Server 2000 7 August 11th, 2008 07:09 PM
Store procedure help ??? RinoDM SQL Server 2000 8 May 1st, 2008 03:03 PM
store procedure if else problem krshekhar SQL Language 0 February 20th, 2008 05:31 AM
Store Procedure sureshyuga SQL Server 2000 0 May 18th, 2007 01:49 AM
Store Procedure Problem jazzcatone ASP.NET 2.0 Basics 3 March 28th, 2006 12:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.