@@ -132,3 +132,83 @@ DELETE FROM employees WHERE age < 30;
132132-- Delete all records
133133DELETE FROM employees;
134134```
135+ ### Transaction Control Language (TCL) 💾
136+
137+ TCL statements are used to manage transactions in the database.
138+
139+ #### COMMIT 💾
140+
141+ Used to save the current transaction.
142+
143+ ``` sql
144+ -- Commit the current transaction
145+ COMMIT ;
146+ ```
147+
148+ #### ROLLBACK ⏪
149+
150+ Used to undo transactions that have not yet been saved.
151+
152+ ``` sql
153+ -- Rollback the current transaction
154+ ROLLBACK ;
155+ ```
156+
157+ #### SAVEPOINT 📍
158+
159+ Used to set a savepoint within a transaction.
160+
161+ ``` sql
162+ -- Set a savepoint
163+ SAVEPOINT sp1;
164+
165+ -- Rollback to the savepoint
166+ ROLLBACK TO SAVEPOINT sp1;
167+ ```
168+
169+ ### Examples 📋
170+
171+ #### Creating and Managing a Database 🛠️
172+
173+ ``` sql
174+ -- Create a new database
175+ CREATE DATABASE company_db ;
176+
177+ -- Use the new database
178+ USE company_db;
179+
180+ -- Create an employees table
181+ CREATE TABLE employees (
182+ id INT PRIMARY KEY ,
183+ name VARCHAR (50 ),
184+ age INT ,
185+ department VARCHAR (50 )
186+ );
187+
188+ -- Add a new column to the employees table
189+ ALTER TABLE employees ADD salary DECIMAL (10 , 2 );
190+
191+ -- Insert records into the employees table
192+ INSERT INTO employees (id, name, age, department, salary) VALUES
193+ (1 , ' John Doe' , 30 , ' HR' , 60000 ),
194+ (2 , ' Jane Smith' , 25 , ' Finance' , 55000 ),
195+ (3 , ' Mike Brown' , 35 , ' IT' , 70000 );
196+
197+ -- Retrieve all employees
198+ SELECT * FROM employees;
199+
200+ -- Update an employee's age
201+ UPDATE employees SET age = 31 WHERE id = 1 ;
202+
203+ -- Delete specific employees
204+ DELETE FROM employees WHERE age < 30 ;
205+
206+ -- Truncate the table
207+ TRUNCATE TABLE employees;
208+
209+ -- Drop the table
210+ DROP TABLE employees;
211+
212+ -- Drop the database
213+ DROP DATABASE company_db;
214+ ```
0 commit comments