473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Stored Procedure Help

CK
I have a one to many relationship between a billing table and a task table.
I want to write a procedure I can pass a billingID to and it will go delete
all the task records with that billingID as well as the as the single
billing record. Like referential integrity.

There are two other task tables taskcharge and taskfunding. When I delete a
task from the task table I want to delete the related records from those two
tables as well.

Bottom line, I want to delete a billing record then delete then child
records in the task table, as they are deleted I need to delete the
taskcharge and taskfunding records child records of the task. The task table
has the billingID field and a taskID field. The taskcharge and taskfunding
tables have the taskID field only.

Can this be done? I suggested trying triggers but this customer doesn't want
to use triggers in delete operations. How do I accomplish this.

Any advice is appreciated.

Thanks in Advance,
CK
Mar 17 '06 #1
5 1108
Look up "Cascading Referential Integrity Constraints" in Transact-SQL Help. This
does it for you!
--
Regards,
Doug Lawry
www.douglawry.webhop.org
"CK" <c_**********@hotmail.com> wrote in message
news:n9*******************@newssvr13.news.prodigy. com...
I have a one to many relationship between a billing table and a task table.
I want to write a procedure I can pass a billingID to and it will go delete
all the task records with that billingID as well as the as the single billing
record. Like referential integrity.

There are two other task tables taskcharge and taskfunding. When I delete a
task from the task table I want to delete the related records from those two
tables as well.

Bottom line, I want to delete a billing record then delete then child records
in the task table, as they are deleted I need to delete the taskcharge and
taskfunding records child records of the task. The task table has the
billingID field and a taskID field. The taskcharge and taskfunding tables
have the taskID field only.

Can this be done? I suggested trying triggers but this customer doesn't want
to use triggers in delete operations. How do I accomplish this.

Any advice is appreciated.

Thanks in Advance,
CK

Mar 17 '06 #2
CK
There were no constraints defined on the tables. Can I do it this way?

ALTER PROC spDeleteBillingContract (@BillingContractID INT)
AS
DELETE FROM TaskOrderCharge WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrderFunding WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrder WHERE BillingContractID=@BillingContractID
DELETE FROM BillingContract WHERE BillingContractID=@BillingContractID

RETURN
"Doug Lawry" <la***@nildram.co.uk> wrote in message
news:dv**********@nntp0.reith.bbc.co.uk...
Look up "Cascading Referential Integrity Constraints" in Transact-SQL
Help. This does it for you!
--
Regards,
Doug Lawry
www.douglawry.webhop.org
"CK" <c_**********@hotmail.com> wrote in message
news:n9*******************@newssvr13.news.prodigy. com...
I have a one to many relationship between a billing table and a task
table.
I want to write a procedure I can pass a billingID to and it will go
delete all the task records with that billingID as well as the as the
single billing record. Like referential integrity.

There are two other task tables taskcharge and taskfunding. When I
delete a task from the task table I want to delete the related records
from those two tables as well.

Bottom line, I want to delete a billing record then delete then child
records in the task table, as they are deleted I need to delete the
taskcharge and taskfunding records child records of the task. The task
table has the billingID field and a taskID field. The taskcharge and
taskfunding tables have the taskID field only.

Can this be done? I suggested trying triggers but this customer doesn't
want to use triggers in delete operations. How do I accomplish this.

Any advice is appreciated.

Thanks in Advance,
CK


Mar 17 '06 #3
Hi CK

That looks like it should work, I would suggest adding "Begin Transaction"
at the start of the SP and "Commit Transaction" at the end. That way you can
be sure all of the rows in the four tables are either deleted or not (should
one step fail for some reason)

Additionally if TaskOrder is a very large table you might consider putting
the TaskOrderIDs to be deleted in a Temp table rather than searching the
TaskOrder Table three times, particularily if TaskOrder.BillingContractID is
not indexed.

--
-Dick Christoph
"CK" <c_**********@hotmail.com> wrote in message
news:jP*****************@newssvr27.news.prodigy.ne t...
There were no constraints defined on the tables. Can I do it this way?

ALTER PROC spDeleteBillingContract (@BillingContractID INT)
AS
DELETE FROM TaskOrderCharge WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrderFunding WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrder WHERE BillingContractID=@BillingContractID
DELETE FROM BillingContract WHERE BillingContractID=@BillingContractID

RETURN
"Doug Lawry" <la***@nildram.co.uk> wrote in message
news:dv**********@nntp0.reith.bbc.co.uk...
Look up "Cascading Referential Integrity Constraints" in Transact-SQL
Help. This does it for you!
--
Regards,
Doug Lawry
www.douglawry.webhop.org
"CK" <c_**********@hotmail.com> wrote in message
news:n9*******************@newssvr13.news.prodigy. com...
I have a one to many relationship between a billing table and a task
table.
I want to write a procedure I can pass a billingID to and it will go
delete all the task records with that billingID as well as the as the
single billing record. Like referential integrity.

There are two other task tables taskcharge and taskfunding. When I
delete a task from the task table I want to delete the related records
from those two tables as well.

Bottom line, I want to delete a billing record then delete then child
records in the task table, as they are deleted I need to delete the
taskcharge and taskfunding records child records of the task. The task
table has the billingID field and a taskID field. The taskcharge and
taskfunding tables have the taskID field only.

Can this be done? I suggested trying triggers but this customer doesn't
want to use triggers in delete operations. How do I accomplish this.

Any advice is appreciated.

Thanks in Advance,
CK



Mar 17 '06 #4
CK
That's much cleaner. Thanks for the tips. Works great!!!

CK

"DickChristoph" <dc********@yahoo.com> wrote in message
news:C0******************@tornado.rdc-kc.rr.com...
Hi CK

That looks like it should work, I would suggest adding "Begin Transaction"
at the start of the SP and "Commit Transaction" at the end. That way you
can be sure all of the rows in the four tables are either deleted or not
(should one step fail for some reason)

Additionally if TaskOrder is a very large table you might consider putting
the TaskOrderIDs to be deleted in a Temp table rather than searching the
TaskOrder Table three times, particularily if TaskOrder.BillingContractID
is not indexed.

--
-Dick Christoph
"CK" <c_**********@hotmail.com> wrote in message
news:jP*****************@newssvr27.news.prodigy.ne t...
There were no constraints defined on the tables. Can I do it this way?

ALTER PROC spDeleteBillingContract (@BillingContractID INT)
AS
DELETE FROM TaskOrderCharge WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrderFunding WHERE TaskOrderID IN
(SELECT TaskOrderID From TaskOrder WHERE
BillingContractID=@BillingContractID)
DELETE FROM TaskOrder WHERE BillingContractID=@BillingContractID
DELETE FROM BillingContract WHERE BillingContractID=@BillingContractID

RETURN
"Doug Lawry" <la***@nildram.co.uk> wrote in message
news:dv**********@nntp0.reith.bbc.co.uk...
Look up "Cascading Referential Integrity Constraints" in Transact-SQL
Help. This does it for you!
--
Regards,
Doug Lawry
www.douglawry.webhop.org
"CK" <c_**********@hotmail.com> wrote in message
news:n9*******************@newssvr13.news.prodigy. com...
I have a one to many relationship between a billing table and a task
table.
I want to write a procedure I can pass a billingID to and it will go
delete all the task records with that billingID as well as the as the
single billing record. Like referential integrity.

There are two other task tables taskcharge and taskfunding. When I
delete a task from the task table I want to delete the related records
from those two tables as well.

Bottom line, I want to delete a billing record then delete then child
records in the task table, as they are deleted I need to delete the
taskcharge and taskfunding records child records of the task. The task
table has the billingID field and a taskID field. The taskcharge and
taskfunding tables have the taskID field only.

Can this be done? I suggested trying triggers but this customer doesn't
want to use triggers in delete operations. How do I accomplish this.

Any advice is appreciated.

Thanks in Advance,
CK



Mar 17 '06 #5
>> There were no constraints defined on the tables.<<

A really bad design flaw that you can correct. Do so.

Also, quit putting "sp_" prefixes on procedure names and follow
ISO-11179 conventions and have "<verb><object>" style names.

Mar 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
3
by: Jarrod Morrison | last post by:
Hi all Im relatively new to using stored procedures and im not sure if it is possible to do what I am trying to do so any help here is greatly appreciated. I am using the variable @MachineName...
7
by: Douglas Buchanan | last post by:
I can't seem to open SQLS2k Stored Procedures in the IDE I am running MDE 2003 Version 7.1.3088 I have a MSDN professional subscription and did a complete install of vs.net Help explains how...
4
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
5
by: microsoft.private.windows.netserver.setup | last post by:
I have a very strange thing occurring in the program. I have a dataset retrieved from a stored procedure that just select * from a table. I then try to use the SQlCommandBuilder on the dataset,...
7
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored...
9
by: jyothi1105 | last post by:
Hi all, Here is some information which could help people who want to create stored procedures and execute them in their program. You can create stored procedures in two ways: Through front end...
0
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.