Rollback Transaction

suggest change

When something fails in a transaction and you want to undo it, roll the transaction back. TRY / CATCH is SQL Server syntax. ROLLBACK undoes the transaction’s changes only if a transaction is still open.

BEGIN TRY
    BEGIN TRANSACTION
        INSERT INTO Users(ID, Name, Age)
        VALUES(1, 'Bob', 24)
        
        DELETE FROM Users WHERE Name = 'Todd'
   COMMIT TRANSACTION
END TRY
BEGIN CATCH
   ROLLBACK TRANSACTION
END CATCH

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents