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 :ermm: