Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Best way to implement transactions in a procedure with If statements Expand / Collapse
Author
Message
Posted Sunday, May 19, 2013 11:18 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, September 11, 2014 4:31 PM
Points: 47, Visits: 286
Hello, I'm writing a complex stored procudere with a lot of IF statements, inside of each IF statement is an Update, Delete or Insert Operation. Example:

CREATE PROC Proc1
@Var1 INT,
@Var2 INT,
@Var3 INT
AS
IF @var1 IS NOT NULL AND @Var2 IS NOT NULL
BEGIN
Update some table
Insert INTO some other table
END
IF @Var1 IS NULL AND @Var2 IS NOT NULL
BEGIN
delete from some table
END
IF @var3 IS NOT NULL AND @Var1 IS NULL AND @Var2 IS NULL
BEGIN
Update Some other table
END

What would be the best approach for using Transactions? Open a transaction inside each statement?
Greetings
Post #1454352
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse