Hi
This statements are executed in Stored Procedure. I am passing parameters and It is doing multiple updates and inserts.
I will appreciate some suggestions to
-improve the performance,
-reduce the execution time
-and improvements in code structure.
There are three different tables: Table_01, Table_02, Table_03.
INSERT INTO Table_01(
TestID,
TestData,
CurrentDate,
UserID,
Status
) VALUES (
@testID,
@testData,
@iDateTime,
@userID,
@Status
)
IF (@Status = 1)
BEGIN
DELETE FROM
Table_02
WHERE
TestID = @testID
UPDATE Table_03
SET
Status = 1,
Date = @iDateTime,
Work = 0
WHERE
TestID = @testID
END
Not really much to tweak to be honest: it’s straightforward code, nothing fancy
You can add a transaction so it all writes succeed or all writes fail.
If you find the code slow then I’d look at indexes on TestID and do you have triggers