Transaction Control Language (TCL) is a subset of SQL used to manage transactions within a database. TCL commands, such as COMMIT, ROLLBACK, and SAVEPOINT, control the execution and outcome of transactions. These commands ensure data integrity by allowing users to commit or rollback changes made during a transaction, or set savepoints to create checkpoints for potential rollbacks. TCL is essential for maintaining consistency and reliability in database operations.
COMMIT: COMMIT is a
Transaction Control Language (TCL) command used to permanently save the changes
made during a transaction. Here's an example and explanation
BEGIN TRANSACTION; UPDATE employees SET salary =
salary * 1.1 WHERE department = 'Sales'; SAVEPOINT before_commit; COMMIT;
In this
example, we’re starting a transaction to ensure that the
subsequent updates are treated as a single unit of work. We then update the
salaries of employees in the 'Sales' department. Before committing the changes
permanently, we set a savepoint to which we can rollback if needed. Finally, we
commit the transaction, making the changes permanent in the database.
ROLLBACK, SAVEPOINT:
ROLLBACK is
a Transaction Control Language (TCL) command used to undo changes made during a
transaction. Here's an example and explanation.
SAVEPOINT
is a Transaction Control Language (TCL) command used to set a named marker
within a transaction. Here's an example and explanation:
BEGIN TRANSACTION; UPDATE employees SET salary =
salary * 1.1 WHERE department = 'Sales'; SAVEPOINT before_commit; ROLLBACK TO
before_commit;
In this
example, we're using ROLLBACK TO to rollback the changes made
during the transaction to a specific savepoint, undoing any modifications made
to the database since that savepoint was set.
Comments
Post a Comment