Sql COMMIT server without Tran | Deal?

According to msdn: commit syntax:

enter image description here

However, when I omit the words tran/ transaction- it compiles and starts with NO errors.enter image description here

How can it work?

Instead, is he doing something else?

+5
source share
2 answers

The COMMIT answer is not really the COMMIT you think. See COMMIT WORK

COMMIT [WORK] [; ]

Note

This statement functions identically to COMMIT TRANSACTION, except that COMMIT TRANSACTION accepts a user-defined username. This COMMIT syntax with or without the optional WORK keyword is compatible with SQL-92.

So COMMIT COMMIT WORK, COMMIT TRANSACTION.
ROLLBACK [ WORK ]

BEGIN TRANSACTION gbn
SELECT 1
COMMIT gbn -- fail
GO
BEGIN TRANSACTION gbn
SELECT 2
COMMIT TRAN gbn -- works
GO
+7

IF @@TRANCOUNT > 0 , ( ) - ROLLBACK, COMMIT,

0

All Articles