I am using SQL Server 2008 Enterprise. I am wondering whether this stored procedure causes deadlock if executed by multiple threads at the same time? Another question is — is it best practices we define begin and end transaction inside of the stored procedure, or defining begin and end transaction from client code (e.g. ADO.Net code)?
create PROCEDURE [dbo].[FooProc]
(
@Param1 int
,@Param2 int
,@Param3 int
)
AS
DELETE FooTable WHERE Param1 = @Param1
INSERT INTO FooTable
(
Param1
,Param2
,Param3
)
VALUES
(
@Param1
,@Param2
,@Param3
)
DECLARE @ID bigint
SET @ID = ISNULL(@@Identity,-1)
IF @ID > 0
BEGIN
SELECT IdentityStr FROM FooTable WHERE ID = @ID
END
thanks in advance,
George
The code you have given could cause deadlock. Even if the stored procedure purely consisted of the following statement deadlock could occur.
Depending upon the exact table definition and indexes available (which you have left out of your question).