Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing a Stored Procedure
Message
From
07/03/2014 15:14:17
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2012
Application:
Desktop
Miscellaneous
Thread ID:
01595936
Message ID:
01595946
Views:
29
>>Hi,
>>
>>I have the following SP which is running very slowly:
>>
>>
CREATE PROCEDURE [dbo].[ManifestHeaderDelete]
>>(
>>	@man_number int
>>)
>>AS
>>	SET NOCOUNT OFF;
>>
>>	delete [dbo].invoicedetails
>>	from [dbo].invoicedetails
>>	inner join invoices on ivd_invfk = inv_pk
>>	inner join AirWayBills on inv_awbfk = awb_pk
>>		  WHERE awb_manifestnumber = @man_number
>>
>>	delete [dbo].invoices
>>	from [dbo].invoices
>>	inner join AirWayBills on inv_awbfk = awb_pk
>>		  WHERE awb_manifestnumber = @man_number
>>
>>	DELETE [dbo].[AirWayBillDetails]
>>	 FROM [dbo].[AirWayBillDetails]
>>	 inner join [dbo].[AirWayBills] on awd_awbfk = awb_pk
>>		  WHERE awb_manifestnumber = @man_number
>>
>>
>>	DELETE [dbo].[AirWayBills]
>>	 FROM [dbo].[AirWayBills]
>>		  WHERE awb_manifestnumber = @man_number
>>
>>
>>	DELETE FROM [dbo].[ManifestHeader]
>>	WHERE 
>>		([man_number] = @man_number)
>>
>>Any advice on optimising this or should I use Cascading deletes based on referential integrity?
>
>CASCADE DELETE sounds like the simplest solution for your case.
>
>Otherwise I would select InvoiceId and InvoiceDetailsID into a temp table and then use it for other delete statements (which need to be in transaction, BTW).

thanks, good point about the transaction.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform