Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 QUery

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-03-16 : 12:00:23
How to avoid deadlocks with the below SP..

create procedure dbo.test as


BEGIN TRY
select * into std1 from student1
END TRY
BEGIN CATCH
EXEC dbo.ErrorInfo_sp 'St1tableERROR'
RETURN
END CATCH


BEGIN TRY
select * into std2 from student2
END TRY
BEGIN CATCH
EXEC dbo.ErrorInfo_sp 'St2tableERROR'
RETURN
END CATCH


BEGIN TRY
Update st1 set name ='test' wehre x=1
END TRY
BEGIN CATCH
EXEC dbo.ErrorInfo_sp 'St1UpdatetableERROR'
END CATCH


BEGIN TRY
update st2 set zipcode='299' where zipcode is null
END TRY
BEGIN CATCH
EXEC dbo.ErrorInfo_sp 'St2UpdatetableERROR'
RETURN
END CATCH

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 12:21:58
i think only common point in above code is dbo.ErrorInfo_sp . what does this sp do?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-03-16 : 13:07:36
Basically it is error info.
-- Create procedure to retrieve error information.
CREATE PROCEDURE dbo.usp_GetErrorInfo
@custom varchar(255)
AS
BEGIN
SET NOCOUNT ON;
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage
,@custom as ErrorCustom;
END
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-16 : 13:35:50
I do this as well

Never have a problem

I guess you use implicit transactions...



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -