From c024e1cf563873106cbc978b875ae2aba2dd1cf5 Mon Sep 17 00:00:00 2001 From: medusa Date: Mon, 11 Mar 2024 05:32:31 +0000 Subject: [PATCH] Update docs/tech_docs/sql_notes.md --- docs/tech_docs/sql_notes.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/tech_docs/sql_notes.md b/docs/tech_docs/sql_notes.md index b4e5462..2218851 100644 --- a/docs/tech_docs/sql_notes.md +++ b/docs/tech_docs/sql_notes.md @@ -68,6 +68,42 @@ DCL includes commands that control access to data in the database. It's used to Understanding DML, DDL, and DCL is crucial for anyone working with SQL databases, as they cover the spectrum of operations from manipulating data to defining the structure of database objects, and controlling access to data. This guide provides a clear overview of these key SQL language components, offering a solid foundation for refreshing knowledge or learning about SQL command categories. +--- +Including Transaction Control Language (TCL) oversight was unintentional. TCL is indeed a crucial aspect of SQL that manages transaction control within the database. It plays a vital role in ensuring data integrity and consistency by managing transaction blocks. Let's expand our reference guide to include TCL and give a complete overview. + +## Transaction Control Language (TCL) + +TCL commands manage the changes made by DML statements. It allows users to control transactions in a database, ensuring that the database remains consistent even in cases of system failure or concurrent access scenarios. TCL commands help in providing a mechanism to either commit a transaction, making all its changes permanent, or rollback a transaction, undoing all changes made since the last commit. + +### COMMIT +- **Purpose**: Makes all changes made during the current transaction permanent and visible to other users. +- **Use Case**: After successfully inserting several records into a table as part of a transaction. +- **Example**: `COMMIT;` + +### ROLLBACK +- **Purpose**: Undoes all changes made in the current transaction, reverting the database state back to what it was before the transaction began. +- **Use Case**: Reverting changes due to an error encountered during a transaction. +- **Example**: `ROLLBACK;` + +### SAVEPOINT +- **Purpose**: Sets a savepoint within a transaction, which you can rollback to without aborting the entire transaction. It's like a checkpoint within a larger transaction. +- **Use Case**: Creating a logical save point within a transaction for a complex operation that may need partial undoing. +- **Example**: `SAVEPOINT savepoint_name;` + +### ROLLBACK TO SAVEPOINT +- **Purpose**: Rolls the transaction back to a specified savepoint, undoing all changes made after the savepoint was set, without terminating the entire transaction. +- **Use Case**: Undoing changes after encountering an error in a transaction past a certain point but not wanting to undo all changes made during the transaction. +- **Example**: `ROLLBACK TO savepoint_name;` + +### SET TRANSACTION +- **Purpose**: Places a name on a transaction. Primarily used in systems that support transaction naming for identifying transactions in database logs. +- **Use Case**: Customizing the isolation level for a transaction or specifying a transaction as read-only or read-write. +- **Example**: `SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;` + +## Conclusion + +TCL is essential for managing the state of transactions within a database, providing tools to commit, rollback, and manage changes effectively. By including TCL alongside DML, DDL, and DCL, our SQL reference guide now offers a more comprehensive overview of SQL's capabilities for managing data, schema objects, access permissions, and transaction integrity within a relational database management system. This inclusion ensures a well-rounded understanding necessary for proficient database operation and management. + --- Creating a more complete SQL reference guide involves encompassing a broad range of SQL syntax, functions, best practices, and advanced concepts. This guide is designed to serve as a comprehensive overview for users at various levels of expertise, offering both a refresher for experienced users and a solid foundation for newcomers.