Following is a SQL Server stored procedure. There is on start of transaction and there are two commits as you can see below. Is this valid (start is in while loop and 1st commit is in same while loop, but 2nd commit is in 2nd while loop)? If not what could be the solution to do it?
Please help.
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DELETE_COBOC_DATA')
DROP PROCEDURE DELETE_COBOC_DATA
GO
CREATE PROCEDURE DELETE_COBOC_DATA @ORGDN VARCHAR(100), @CHUNK VARCHAR(10)
AS
BEGIN
-- some code that executes before while
WHILE (@NUM_ROWS_TMPTRADMIN > 0)
BEGIN
BEGIN TRANSACTION
-- executes some code
COMMIT TRANSACTION
END
-- some more code
WHILE @NUM_ROWS_TMPDIR > 0
BEGIN
-- code code code
COMMIT TRANSACTION
-- code code code
END
-- some more code here as well
END
As I know this is allowed in MySQL
You cannot commit the same transaction twice. You can have nested transactions, but you cannot have "partial" commits, that is contradictory to the notion of a transaction (it's all-or-nothing). If both commits are executed, the second one will throw an error
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With