SQL Transaction Usage
Simply put, a transaction is a mechanism for maintaining the integrity of the database.
Its implementation form is to embed ordinary SQL statements into the BEGIN Tran ... Commit Tran (or full form Begin Transaction ... Commit Transaction), and, of course, you can use rollback Tran to roll back the transaction if necessary, that is, undo the operation.
Using the transaction mechanism, the operation of the database is all executed, or all is not executed, to ensure the consistency of the database. SQL statements that require the use of transactions are usually update and delete operations, and so on.
It is important to note that a transaction does not support nesting, that is, a form similar to this is not allowed:
Begin Tran
...
Begin Tran
...
Commit Tran
...
Commit Tran
Of course, the query does not have to use transactions because the query does not change the data and does not break the integrity.
The display transaction is marked with the BEGIN TRANSACTION and end transaction, where the update and DELETE statements are either executed or all are not performed. Such as:
BEGIN TRANSACTION T1
Update student
Set Name= ' Tank '
where id=2006010
Delete from student
where id=2006011
Commit
End Transaction T1