Files
Files
Theory-
Transaction Control Language (TCL) commands are used to manage the integrity and consistency of
transactions in a database. A transaction is a sequence of SQL operations executed as a single unit, and
TCL commands help ensure that these operations are completed correctly. The COMMIT command
finalizes a transaction, making all changes made during it permanent. This is essential for ensuring that
all operations within a transaction are saved to the database. Conversely, the ROLLBACK command
reverts the database to its state before the transaction began, effectively undoing all changes if an error
occurs or if a decision is made to cancel the transaction. The SAVEPOINT command allows setting a
specific point within a transaction to which you can roll back without affecting the entire transaction,
providing more granular control over changes Together, these TCL commands ensure that database
operations are handled reliably and that data integrity is maintained throughout complex transactions.
TCL Commands:
1. COMMIT
- Description: Finalizes the current transaction and makes all changes permanent.
- Syntax: COMMIT;
- Examples:
INSERT INTO Employees (EmployeeID, LastName, FirstName) VALUES (3, 'Brown', 'Alice');
COMMIT;
2. ROLLBACK
- Description: Reverts the database to the state before the current transaction began.
- Syntax: ROLLBACK;
- Examples:
ROLLBACK;
3. SAVEPOINT
- Description: Sets a point within a transaction that you can roll back to, allowing partial undo of
operations.
- Syntax:
SAVEPOINT savepoint_name;
- Examples:
SAVEPOINT before_update;
UPDATE Employees SET LastName = 'Doe' WHERE EmployeeID = 1;
2. Data Control Language (DCL) commands are essential for managing user permissions and access
control within a database. The GRANT command is used to assign specific privileges to users or roles,
such as the ability to SELECT, INSERT, UPDATE, or DELETE data from tables. This allows database
administrators to control who can access or modify data, which is crucial for maintaining security and
protecting sensitive information. On the other hand, the REVOKE command is used to remove these
privileges when they are no longer necessary. By revoking permissions, administrators can ensure that
access is restricted based on user roles and responsibilities, thereby enforcing data security policies.
The Data Control language (DCL) commands are also in Transaction Control Language(TCL) but they are
included in Data Control Language (DCL) .
DCL Commands:
1. GRANT
- Description: Provides specific privileges to users or roles on database objects such as tables, views, or
procedures.
- Syntax:
- Examples:
2. REVOKE
- Syntax:
- Examples: