TCL OPERATIONS:
- TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.
Command
|
Description
|
Commit | Used to save any transaction permanently. |
Rollback | This command Is used to restore database to its last committed state. |
Save Tran | This command is used to save the transaction so that we can rollback that transaction to the point whenever necessary. |
For example, we have a table named "tblStudent" with 3 records as shown below.
Now we'll begin our transaction and add another record and commit that transaction.
Now we'll begin our transaction and add another record and commit that transaction.
- Begin Tran
- Insert INTO tblStudents VALUES ('Sumit')
- COMMIT
Now, we'll add three records, one by one with save point, but we don't commit our transaction.
- Begin Tran
- Insert INTO tblStudents VALUES ('Kajal')
- SAVE Tran A;
- Insert INTO tblStudents VALUES ('Rahul')
- SAVE Tran B;
- Insert INTO tblStudents VALUES ('Ram')
- SAVE Tran C;
- SELECT * from tblStudents
Now we have 3 savepoints, in other words A, B and C. Since our transaction is not yet committed, we can roll it back to any savepoint. We'll roll it back to point B, in other words at "Rahul".
- ROLLBACK TRAN B
- COMMIT
So this was the article based on types of commands in SQL Server with which you can play with data stored in SQL Server.
In this article, we have seen the types of commands in SQL Server and done some overview of that. We have also seen how to commit transactions and how to roll back any transaction to any saved point.
In my next article, we'll be explaining how to deal with the GRANT and REVOKE commands. Until then keep learning and keep sharing.
If there's any mistake in this article then please let me know. Please provide your valuable feedback and comments that enable me to provide a better article the next time.
Comments
Post a Comment