SQL - Structured Query Language |
BEGIN TransactionBEGIN Transaction is marks the starting point of an explicit local transaction. Syntax -- Syntax --
BEGIN { TRAN | TRANSACTION } [ { transaction_name | @tran_name_variable } [ WITH MARK [ 'description' ] ] ] [ ; ] Transaction Name Transaction Name is the name assigned to the transaction that must conform to the rules of identifier. Define transaction names only on the outermost pair of nested BEGIN ... COMMIT or BEGIN ... ROLLBACK statements. @Tran_Name_Variable @Tran_Name_Variable is the name of the user-defined variable containing a valid transaction name. The variable must be declared with a char, varchar, nchar, or nvarchar data type only. WITH MARK ['description'] WITH MARK ['description'] is specifies that the transaction is marked in the log description is a string that describes the mark. A description longer than 128 characters is truncated to 128 characters before being stored in the msdb.dbo.logmarkhistory table. Naming a Transaction Example The following example is used to update particular Employee Name. -- Example 63 --
SELECT * FROM EMP
BEGIN TRANSACTION MyTransaction
USE EBusiness GO
UPDATE EMP SET Emp_Name = 'Employee 50001' WHERE Emp_Code = 501;
COMMIT TRANSACTION MyTransaction GO
SELECT * FROM EMP Query Output Screen Marking a Transaction Example The following example is used to update particular Employee Name. -- Example 64 --
SELECT * FROM EMP
BEGIN TRANSACTION UpdateEmployeeName WITH MARK N'Updating an Employee Name'; GO
USE EBusiness GO
UPDATE EMP SET Emp_Name = 'Employee 51' WHERE Emp_Code = 501;
COMMIT TRANSACTION UpdateEmployeeName; GO
SELECT * FROM EMP Query Output Screen |
* * * * *