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 2000 Forums
 SQL Server Development (2000)
 Transaction Question

Author  Topic 

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2005-02-01 : 10:15:01
Hi guys.

I have a few stored procedures that perform a single sql statement to insert, update, and delete information out of the database. I was wondering if for these simple stored procedures do I need to wrap the single statements in a transaction? I believe I read somewhere where its not necessary but I wanted to hear what you guys think on this issue.


Heres my sample stored procedure.


/*
Procedure that deletes all of the item locks for a particular user.
*/
CREATE PROCEDURE dbo.DeleteLocksForUser
(
@UserID int
)
AS
SET NOCOUNT ON

DELETE FROM dbo.ItemLock
WHERE dbo.ItemLock.UserID = @UserID
GO


Dustin Michaels

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-02-01 : 10:55:45
What you read was correct. SqlServer implicitly "wraps" every individual statement in a transaction. To override that functionality and force an "All or None" situation on several statements, the developer can wrap those statements in an explicit transaction.

Be One with the Optimizer
TG
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-01 : 11:03:35
you can look at it this way: one statement one transaction. if that one fails for whatever reason, nothing will change.

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -