EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Database Management Tutorial Transaction Control Language
Secondary Sidebar
Database Management Tutorial
  • DataBase Management
    • Text Data Mining
    • Roles of Database Management System in Industry
    • SQL Server Database Management Tools
    • Databricks CLI
    • Database administrator skills
    • Database Management Systems Advantages
    • Database Testing Interview Questions
    • Netezza Database
    • Data Administrator
    • Database Administrator
    • Data manipulation
    • Database Management Software
    • DataStage
    • Types of Database Models
    • Types of Database
    • Hierarchical Database Model
    • Relational Database
    • Relational Database Advantages
    • Operational Database
    • What is RDBMS?
    • Data Masking Tools
    • Database Security
    • Data Replication
    • Bitmap Indexing
    • Second Normal Form
    • Third Normal Form
    • Fourth Normal Form
    • Data Definition Language
    • Data Manipulation Language
    • Data Control Language
    • Transaction Control Language
    • Dataset Normalization
    • jdbc connection
    • Conceptual Data Model
    • Entity-Relationship Model
    • Relational Database Model
    • Sequential File Organization
    • Teradata Create Table
    • Teradata Database
    • Centralized Database
    • Data Storage in Database
    • Thomas write Rule
    • DBA Interview Questions
    • What is JDBC?
    • jdbc hive
    • Apriori Algorithm
    • JDBC Architecture
    • JDBC Interview Questions
    • Datastage Interview Questions
    • Wildcard Characters
    • Distributed Database System
    • Multidimensional Database
  • TSQL Basic
    • TSQL
    • What is T-SQL
    • T-SQL Commands
    • T-SQL String Functions
    • TSQL Interview Questions

Related Courses

SQL Certification Course

PL/SQL Certification Course

Oracle Certification Course

Transaction Control Language

By Priya PedamkarPriya Pedamkar

Transaction Control Language

Introduction to Transaction Control Language

In a Relational Database Management System (RDBMS), the Structured Query Language (SQL) is used to perform multiple operations to store, retrieve and manipulate the data across various tables in a database. Let us consider few scenarios where we might have updated a record mistakenly and want to restore the data or we have inserted few records and want to save them, there Transaction Control Language (TCL) comes into the picture. The Transaction Control Language is used to maintain the integrity and consistency of the data stored in the database.

Needs of Transaction Control Language

The Transaction Control Language manages the changes in the data which are made by the DML operations. The alteration made by the DML commands such as UPDATE, INSERT or DELETE is not permanent and these changes can be canceled before the present session gets closed. To control the changes and processing of data, TCL is used simultaneously with the Data Manipulation Language. As we perform many operations on the data, the database might become inconsistent between the transactions.

So the Transaction Control Language (TCL) is used to maintain consistency and manage the transaction in a database. After the commit is performed the database state is changed from one to another consistent state. The Transactions are used on all the DDL and DML queries automatically.

How does Transaction Control Language Work?

A transaction in a database is a logical unit of processing which may comprise of one or more database operations. A series of low-level changes into a logical update are grouped together by using a transaction. For example, a transaction might be updating a single value or updating of a complex procedure such as the insertion of multiple rows to different tables. Normally, a transaction is started and then as the individual DML commands are executed, they become the part of the transaction and when the logical procedure is over, the transaction gets committed. The commit command ensures that the changes are made permanent in the database. If the commit operation fails, the transaction gets rolled back and all the changes are removed.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

TCL Commands with Examples

The commands in Transaction Control Language are Commit, Rollback, and Savepoint.

1. COMMIT

This command is used to make a transaction permanent in a database. So it can be said that commit command saves the work done as it ends the current transaction by making permanent changes during the transaction. The syntax for this command is as below.

COMMIT;

For instance, we want to update the location of an employee in the table “EMPLOYEE”. Sample EMPLOYEE table is given below:

EMP_ID EMP_NAME EMP_LOC
1356 Raju Delhi
2678 Neeta Bangalore
9899 Sanjay Hyderabad

Let us update the EMP_ LOC for Raju as below:

Query:

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,584 ratings)

UPDATE EMPLOYEE SET EMP_ LOC = 'Hyderabad' WHERE EMP_NAME= 'Raju';
COMMIT;

The update transaction is completed with the commit command as above and the usage of the above statements will update the location of the employee ‘Raju’ and the change will be saved in the database permanently.

The updated table is as shown below:

EMP_ID EMP_NAME EMP_LOC
1356 Raju Hyderabad
2678 Neeta Bangalore
9899 Sanjay Hyderabad

2. ROLLBACK

This command is used to restore the database to its original state since the last command that was committed. The syntax of the Rollback command is as below:

ROLLBACK;

Also, the ROLLBACK command is used along with savepoint command to leap to a save point in a transaction. The syntax for the same is as below:

ROLLBACK TO <savepoint_name>;

Let us take the example of the EMPLOYEE table as cited above. Let us consider that we have updated EMP_LOC for Raju to Bangalore later and realize that the update was done mistakenly as below. Then we can restore the EMP_LOC for ‘Raju’ to Hyderabad again by using the Rollback command as below.

Query:

UPDATE EMPLOYEE SET EMP_LOC= 'Bangalore' WHERE EMP_NAME = 'Raju';
ROLLBACK;

After the wrong update the table is as below:

EMP_ID EMP_NAME EMP_LOC
1356 Raju Bangalore
2678 Neeta Bangalore
9899 Sanjay Hyderabad

After the Rollback is performed, the location for Raju is restored to the last committed state as shown below.

EMP_ID EMP_NAME EMP_LOC
1356 Raju Hyderabad
2678 Neeta Bangalore
9899 Sanjay Hyderabad

3. SAVEPOINT

This command is used to save the transaction temporarily. So the users can rollback to the required point of the transaction. The syntax for using this command is as below:

SAVEPOINT savepoint_name;

Let us take the example of a table “ORDERS” with columns as ORDER_ID and ITEM_NAME.

ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA

Let us insert the below values to the ORDERS table below and perform the updates using savepoint.

Query:

INSERT INTO ORDERS VALUES ('355' , 'CELL PHONE');
COMMIT;
UPDATE ORDERS SET ITEM_NAME = 'SMART PHONE' WHERE ORDER_ID= '355';
SAVEPOINT A;
INSERT INTO ORDERS VALUES ('566' , 'BLENDER');
SAVEPOINT B;
Now the ORDERS table will be as below:

Now the ORDERS table will be as below:

ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
355 SMART PHONE
566 BLENDER

Now we can use the SAVEPOINT command to Rollback the transaction. Let us Rollback the transaction to savepoint A.

Query:

ROLLBACK TO A;

The ORDERS table will be as below:

ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
355 SMART PHONE

Advantages of Transaction Control Language

The Transaction Control Language provides the privilege to rollback the transaction if the data is updated in the tables by mistake. It performs a permanent change to the database by locking the data using the commit command. Also with the help of savepoint command, users can save the transactions temporarily and if required, can also perform rollback using the savepoint.

Conclusion

Transaction Control Language helps in maintaining the consistency and integrity of the data. The database can be restored to the last committed state as well as modifications made can be saved permanently with the help of TCL. The developers should have a keen understanding of TCL to build a robust system.

Recommended Articles

This is a guide to Transaction Control Language. Here we discuss the working and different commands of transaction control language with their examples and code implementation. You may also have a look at the following articles to learn more –

  1. Types of Hashing in DBMS
  2. Types of DBMS Architecture
  3. Different Types of NoSQL Databases
  4. List of Database Management Systems
  5. Learn the Top 7 Types of DBMS
  6. Guide to Top 8 Advantages of Relational Database
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

SQL Training Program (7 Courses, 8+ Projects)4.9
PL SQL Training (4 Courses, 2+ Projects)4.8
Oracle Training (14 Courses, 8+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more