p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Database > SQL Language
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 23rd, 2009, 11:14 PM
Friend of Wrox
Points: 577, Level: 8
Points: 577, Level: 8 Points: 577, Level: 8 Points: 577, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 24th, 2009, 01:41 AM
Friend of Wrox
Points: 1,882, Level: 17
Points: 1,882, Level: 17 Points: 1,882, Level: 17 Points: 1,882, Level: 17
Activity: 7%
Activity: 7% Activity: 7% Activity: 7%
 
Join Date: May 2004
Location: India
Posts: 563
Thanks: 0
Thanked 14 Times in 14 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Store procedure help... RinoDM SQL Server 2000 7 August 11th, 2008 08:09 PM
Store procedure help ??? RinoDM SQL Server 2000 8 May 1st, 2008 04: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 02:49 AM
Store Procedure Problem jazzcatone ASP.NET 2.0 Basics 3 March 28th, 2006 12:41 AM



All times are GMT -4. The time now is 01:01 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc