Wednesday, December 24, 2014

Transaction:IMPLICIT - Explicit Transactions

Source:SET IMPLICIT_TRANSACTIONS (Transact-SQL)


SET IMPLICIT_TRANSACTIONS { ON | OFF }
When OFF, it returns the connection to autocommit transaction mode

...
When SET ANSI_DEFAULTS is ON, SET IMPLICIT_TRANSACTIONS is ON.

...

Source:Explicit Transactions


An explicit transaction is one in which you explicitly define both the start and end of the transaction.
DB-Library applications and Transact-SQL scripts use the BEGIN TRANSACTION, COMMIT TRANSACTION, COMMIT WORK, ROLLBACK TRANSACTION, or ROLLBACK WORK Transact-SQL statements to define explicit transactions.
BEGIN TRANSACTION
Marks the starting point of an explicit transaction for a connection.
COMMIT TRANSACTION or COMMIT WORK 
 Source:What does a transaction around a singlestatement do?
...
In MS-SQL, is there any benefit from wrapping single selects, single updates, single inserts or single deletes in a transaction?
...
 
It does nothing. All individual SQL Statements, (with rare exceptions like Bulk Inserts with No Log, or Truncate Table) are automaticaly "In a Transaction" whether you explicitly say so or not.. (even if they insert, update, or delete millions of rows).
...
...
"ACID" requirements of a relational database? That "A" stands for Atomic, meaning that either the statement works in its entirety, or it doesn't--and while the statement is being performed, no other queries can be done on the data affected by that query. BEGIN TRANSACTION / COMMIT "extends" this locking functionality to the work done by multiple statements, but it adds nothing to single statements.
...
Note also that "nolock" does not apply to inserts/updates/deletes -- those actions always required locks.



 

 

No comments:

Post a Comment