{"id":92554,"date":"2024-04-17T12:15:35","date_gmt":"2024-04-17T06:45:35","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/"},"modified":"2025-05-17T01:22:49","modified_gmt":"2025-05-16T19:52:49","slug":"sql-commands","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","title":{"rendered":"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples"},"content":{"rendered":"\n<p><strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/\">SQL<\/a>(Structured Query Language)<\/strong> is the standard language for managing and manipulating relational databases. SQL commands are the instructions used to communicate with a Relational Database Management System (<a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-rdbms\/\">RDBMS<\/a>) to create database structures, manipulate data, and control access.<\/p>\n\n\n\n<p>Whether you need to build a new table, update customer records, or retrieve a specific dataset, you will use specific subsets of SQL. <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">This comprehensive guide covers the five main categories of SQL commands, s<\/span>uch as&nbsp;DDL, DML, DQL, DCL, and TCL,&nbsp;complete with definitions, syntax, and practical code examples.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-title-link\">SQL Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master SQL and Database management with this SQL course: Practical training with guided projects, AI support, and expert instructors.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>7 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-button\">\n                Take SQL Course Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-commands-cheat-sheet\">SQL Commands Cheat Sheet<\/h2>\n\n\n\n<p>A quick reference for the most common commands.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Category<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>ALTER<\/td><td>DDL<\/td><td>Adds or modifies columns in a table.<\/td><\/tr><tr><td>COMMIT<\/td><td>TCL<\/td><td>Saves changes permanently.<\/td><\/tr><tr><td>CREATE<\/td><td>DDL<\/td><td>Creates a new table or database.<\/td><\/tr><tr><td>DELETE<\/td><td>DML<\/td><td>Removes rows from a table.<\/td><\/tr><tr><td>DROP<\/td><td>DDL<\/td><td>Deletes a table entirely.<\/td><\/tr><tr><td>GRANT<\/td><td>DCL<\/td><td>Gives a user access permissions.<\/td><\/tr><tr><td>INSERT<\/td><td>DML<\/td><td>Adds new rows to a table.<\/td><\/tr><tr><td>MERGE <\/td><td>DML <\/td><td>Conditionally inserts, updates, or deletes data (Upsert)<\/td><\/tr><tr><td>ROLLBACK<\/td><td>TCL<\/td><td>Undoes recent changes.<\/td><\/tr><tr><td>SELECT<\/td><td>DQL<\/td><td>Retrieves data.<\/td><\/tr><tr><td>TRUNCATE<\/td><td>DDL<\/td><td>Wipes all data but keeps the table.<\/td><\/tr><tr><td>UPDATE<\/td><td>DML<\/td><td>Edits existing data.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-title-link\">SQL Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master SQL and Database management with this SQL course: Practical training with guided projects, AI support, and expert instructors.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>7 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-button\">\n                Take SQL Course Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"data-definition-language-ddl\">Data Definition Language (DDL)<\/h2>\n\n\n\n<p><strong>Data Definition Language (DDL)<\/strong> commands define and manage the structure (schema) of your database. They allow you to create, modify, or delete database objects such as tables, indexes, and views.<\/p>\n\n\n\n<p><strong>Note<\/strong>: In most relational databases (like Oracle and MySQL), DDL commands are <strong>auto-committed<\/strong>. This means once you execute a <strong><code>DROP<\/code> <\/strong>or <strong><code>TRUNCATE<\/code> <\/strong>command, the change is permanent and cannot be undone using a <strong><code>ROLLBACK<\/code> <\/strong>command.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/ddl.png\"><img decoding=\"async\" width=\"354\" height=\"532\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/ddl.png\" alt=\"Data Definition Language (DDL) Commands\" class=\"wp-image-107544\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/ddl.png 354w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/ddl-200x300.png 200w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/ddl-150x225.png 150w\" sizes=\"(max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<p><strong>1. CREATE:<\/strong><\/p>\n\n\n\n<p>Creates a new database or table.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE TABLE Employees (\n    ID INT PRIMARY KEY,\n    Name VARCHAR(100),\n    Age INT,\n    Department VARCHAR(50)\n);\n<\/pre><\/div>\n\n\n<p><strong>2. ALTER:<\/strong><\/p>\n\n\n\n<p>Modifies the structure of an existing table (e.g., adding, deleting, or modifying columns).<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nALTER TABLE Employees\nADD Salary DECIMAL(10, 2);\n<\/pre><\/div>\n\n\n<p><strong>3. DROP:<\/strong><\/p>\n\n\n\n<p>Deletes a table and all its data permanently.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDROP TABLE Employees;\n<\/pre><\/div>\n\n\n<p><strong>4. TRUNCATE:<\/strong><\/p>\n\n\n\n<p>Deletes all data inside a table but keeps the structure.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nTRUNCATE TABLE Employees;\n<\/pre><\/div>\n\n\n<p><strong>5. RENAME:<\/strong><\/p>\n\n\n\n<p>Changes the name of a database object (like a table or column).<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nRENAME TABLE Employees TO Staff;\n<\/pre><\/div>\n\n\n<p><strong>6. COMMENT:<\/strong><\/p>\n\n\n\n<p>Adds or modifies a comment on a database object (like a table or column).<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCOMMENT ON COLUMN Employees.Name IS &#039;Employee Name&#039;;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"essential-sql-constraints\"><strong>Essential SQL Constraints<\/strong><\/h3>\n\n\n\n<p>When using the CREATE TABLE DDL command, you will often apply constraints to specify rules for the data in a table. Common constraints include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>PRIMARY KEY:<\/strong> Uniquely identifies each record in a table (e.g., Employee ID). Cannot contain NULL values.<\/li>\n\n\n\n<li><strong>FOREIGN KEY:<\/strong> A field in one table that refers to the PRIMARY KEY in another table, linking them together.<\/li>\n\n\n\n<li><strong>NOT NULL:<\/strong> Ensures that a column cannot have a NULL value.<\/li>\n\n\n\n<li><strong>UNIQUE:<\/strong> Ensures that all values in a column are different.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"data-manipulation-language-dml\">Data Manipulation Language (DML)<\/h2>\n\n\n\n<p><strong>DML<\/strong> commands manage the data within your database. They allow you to add, edit, or remove records in the tables, working with the data inside the structure created by DDL.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/DML.png\"><img decoding=\"async\" width=\"354\" height=\"532\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/DML.png\" alt=\"Data Manipulation Language (DML) Commands\" class=\"wp-image-107548\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/DML.png 354w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/DML-200x300.png 200w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/DML-150x225.png 150w\" sizes=\"(max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<p><strong>7. INSERT:<\/strong><\/p>\n\n\n\n<p>Adds new records to a table.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nINSERT INTO Employees (ID, Name, Age, Department) \nVALUES (1, &#039;John Doe&#039;, 30, &#039;HR&#039;);\n<\/pre><\/div>\n\n\n<p><strong>8. UPDATE:<\/strong><\/p>\n\n\n\n<p>Modifies existing records in a table.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nUPDATE Employees\nSET Age = 31\nWHERE ID = 1;\n<\/pre><\/div>\n\n\n<p><strong>9. DELETE:<\/strong><\/p>\n\n\n\n<p>Removes records from a table.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDELETE FROM Employees\nWHERE ID = 1;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"delete-vs-truncate-vs-drop-whats-the-difference\"><strong>DELETE vs. TRUNCATE vs. DROP: What\u2019s the Difference?<\/strong><\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>One of the most common SQL interview questions is explaining the difference between these three deletion commands. Here is a quick comparison to help you choose the right one:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>Feature<\/strong><\/th><th><strong>DELETE<\/strong><\/th><th><strong>TRUNCATE<\/strong><\/th><th><strong>DROP<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>Command Type<\/strong><\/td><td>DML (Data Manipulation Language)<\/td><td>DDL (Data Definition Language)<\/td><td>DDL (Data Definition Language)<\/td><\/tr><tr><td><strong>Action<\/strong><\/td><td>Removes specific rows based on a WHERE condition.<\/td><td>Removes ALL rows from a table, but keeps the table structure.<\/td><td>Deletes the entire table structure and all its data permanently.<\/td><\/tr><tr><td><strong>Rollback<\/strong><\/td><td>Can be rolled back (undone).<\/td><td>Cannot be rolled back (in most databases).<\/td><td>Cannot be rolled back.<\/td><\/tr><tr><td><strong>Speed<\/strong><\/td><td>Slower (logs each row deletion).<\/td><td>Faster (deletes data pages).<\/td><td>Fastest.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"data-control-language-dcl\">Data Control Language (DCL)<\/h2>\n\n\n\n<p><strong>DCL<\/strong> commands manage security, access, and permissions. They control who can view or edit data, ensuring only authorized users can modify sensitive information.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/dcl.png\"><img decoding=\"async\" width=\"347\" height=\"273\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/dcl.png\" alt=\"Data Control Language (DCL) Commands.\" class=\"wp-image-107552\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/dcl.png 347w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/dcl-300x236.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/dcl-150x118.png 150w\" sizes=\"(max-width: 347px) 100vw, 347px\" \/><\/figure>\n\n\n\n<p><strong>10. GRANT:<\/strong><\/p>\n\n\n\n<p>This command gives permissions to users or roles. You can grant permissions such as SELECT (view), INSERT (add data), UPDATE (modify data), and DELETE (remove data).<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nGRANT SELECT, INSERT ON Employees TO user123;\n<\/pre><\/div>\n\n\n<p><strong>11. REVOKE:<\/strong><\/p>\n\n\n\n<p>This command removes permissions from users or roles. It takes away rights that were previously granted. You can revoke permissions like SELECT, INSERT, UPDATE, or DELETE.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nREVOKE SELECT, INSERT ON Employees FROM user123;\n<\/pre><\/div>\n\n\n<p><strong>12. DENY:<\/strong><\/p>\n\n\n\n<p>While <strong><code>GRANT<\/code> <\/strong>and <strong><code>REVOKE<\/code> <\/strong>are universal standard SQL commands, <strong><code>DENY<\/code> <\/strong>is specifically used in Microsoft SQL Server (T-SQL). It explicitly prevents a user or role from gaining a permission, overriding any permissions they might have inherited from other group memberships.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDENY DELETE ON Employees TO user123;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"data-query-language-dql\">Data Query Language (DQL)<\/h2>\n\n\n\n<p><strong>DQL<\/strong> commands are used to retrieve data from the database. It focuses only on reading information, not changing it.<\/p>\n\n\n\n<p>The primary DQL command is SELECT. It can be combined with clauses like WHERE, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-joins\/\">JOIN<\/a>, and HAVING to refine results and analyze data in detail.<\/p>\n\n\n\n<p><strong>13. SELECT:<\/strong><\/p>\n\n\n\n<p>The SELECT command retrieves data from a database using clauses such as WHERE, JOIN, and HAVING to refine and filter the results.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT Name, Age FROM Employees WHERE Department = &#039;Sales&#039;;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"essential-dql-clauses-and-aggregate-functions\"><strong>Essential DQL Clauses and Aggregate Functions<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"1-the-where-clause\"><strong>1. The WHERE Clause<\/strong><\/h4>\n\n\n\n<p>Used to filter records that fulfill a specified condition. Retrieve employees who work in Sales<\/p>\n\n\n\n<p>SELECT Name, Age<br>FROM Employees<br>WHERE Department = 'Sales';<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"2-the-order-by-clause\"><strong>2. The ORDER BY Clause<\/strong><\/h4>\n\n\n\n<p>Sorts the result set in ascending (ASC) or descending (DESC) order.Sort employees by highest salary.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT Name, Salary\nFROM Employees\nORDER BY Salary DESC;\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"3-group-by-and-having-clauses\"><strong>3. GROUP BY and HAVING Clauses<\/strong><\/h4>\n\n\n\n<p>GROUP BY groups rows that have the same values into summary rows. HAVING is used instead of WHERE with aggregate functions. Find departments with an average salary greater than 55000.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT Department, AVG(Salary) as AvgSalary\nFROM Employees\nGROUP BY Department\nHAVING AVG(Salary) &gt; 55000;\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"4-sql-aggregate-functions\"><strong>4. SQL Aggregate Functions<\/strong><\/h4>\n\n\n\n<p>Aggregate functions perform a calculation on a set of values and return a single value. The most common are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>COUNT():<\/strong> Returns the number of rows.<\/li>\n\n\n\n<li><strong>SUM():<\/strong> Returns the total sum of a numeric column.<\/li>\n\n\n\n<li><strong>AVG():<\/strong> Returns the average value of a numeric column.<\/li>\n\n\n\n<li><strong>MAX() \/ MIN():<\/strong> Returns the highest\/lowest value.<\/li>\n<\/ul>\n\n\n\n<p>Count the total number of employees in the company<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT COUNT(*) FROM Employees;\n<\/pre><\/div>\n\n\n<p>Find the highest salary in the IT department<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT MAX(Salary) FROM Employees WHERE Department = &#039;IT&#039;;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"other-queries\">Other Queries<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT + WHERE + ORDER BY\nSELECT Name, Salary FROM Employees WHERE Salary &gt; 50000 ORDER BY Salary DESC;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT + JOIN\nSELECT Employees.Name, Departments. Name AS DeptName FROM Employees JOIN Departments ON Employees.DeptID = Departments.ID;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT + GROUP BY + HAVING\nSELECT Department, COUNT() AS TotalEmployees FROM Employees GROUP BY Department HAVING COUNT() &gt; 10;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT + DISTINCT\nSELECT DISTINCT Department FROM Employees;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT + ORDER BY + LIMIT\nSELECT Name, Age FROM Employees ORDER BY Age DESC LIMIT 5;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"transaction-control-language-tcl\">Transaction Control Language (TCL)<\/h2>\n\n\n\n<p><strong>TCL<\/strong> is a set of SQL commands used to manage transactions. A transaction is a group of SQL operations that should be treated as a single unit. TCL ensures that either all actions in a transaction are saved, or none are saved if something goes wrong.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/tcl.png\"><img decoding=\"async\" width=\"349\" height=\"368\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/tcl.png\" alt=\"Transaction Control Language (TCL) Commands\" class=\"wp-image-107557\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/tcl.png 349w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/tcl-285x300.png 285w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/tcl-150x158.png 150w\" sizes=\"(max-width: 349px) 100vw, 349px\" \/><\/figure>\n\n\n\n<p>The TCL commands are:<\/p>\n\n\n\n<p><strong>14. COMMIT<\/strong><\/p>\n\n\n\n<p>The <strong><code>COMMIT<\/code> <\/strong>command permanently saves all changes made during the current transaction to the database. Once committed, the changes are visible to other users and cannot be rolled back.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- Note: Syntax for starting a transaction varies by RDBMS. \n-- SQL Server uses BEGIN TRANSACTION, PostgreSQL uses BEGIN, and MySQL uses START TRANSACTION.\nBEGIN TRANSACTION;\nUPDATE employees SET salary = 5000 WHERE id = 1;\nCOMMIT;\n<\/pre><\/div>\n\n\n<p>In this example, the salary update is saved to the database.<\/p>\n\n\n\n<p><strong>15. ROLLBACK<\/strong><\/p>\n\n\n\n<p>The ROLLBACK command undoes all mistaken changes made during the current transaction.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nBEGIN TRANSACTION;\nUPDATE employees SET salary = 5000 WHERE id = 1;\nROLLBACK;\n<\/pre><\/div>\n\n\n<p>Here, the salary update is undone, and the data remains unchanged.<\/p>\n\n\n\n<p><strong>16. SAVEPOINT<\/strong><\/p>\n\n\n\n<p>The SAVEPOINT command sets a point within a transaction that you can roll back to if needed.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nBEGIN TRANSACTION;\nUPDATE employees SET salary = 5000 WHERE id = 1;\nSAVEPOINT salary_update;\nUPDATE employees SET salary = 6000 WHERE id = 2;\nROLLBACK TO salary_update;\nCOMMIT;\n<\/pre><\/div>\n\n\n<p>In this example, if the second update causes an issue, you can roll back to the salary_update point, keeping the first update intact.<\/p>\n\n\n\n<p><strong>17. SET TRANSACTION<\/strong><\/p>\n\n\n\n<p>The SET TRANSACTION command is used to set properties for the current transaction, such as isolation level.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;\nBEGIN TRANSACTION;\nUPDATE employees SET salary = 5000 WHERE id = 1;\nCOMMIT;\n<\/pre><\/div>\n\n\n<p>This sets the isolation level to SERIALIZABLE, ensuring that no other transactions can access the data until the current transaction completes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faqs\">FAQs<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1778645514591\"><strong class=\"schema-faq-question\"><strong>What are the 5 main types of SQL commands?<\/strong><\/strong> <p class=\"schema-faq-answer\">The five main types of SQL commands are DDL (Data Definition Language) for defining structures, DML (Data Manipulation Language) for managing data, DQL (Data Query Language) for retrieving data, DCL (Data Control Language) for managing permissions, and TCL (Transaction Control Language) for handling database transactions.<br><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778645546962\"><strong class=\"schema-faq-question\"><strong>What is the difference between DDL and DML?<\/strong><\/strong> <p class=\"schema-faq-answer\">DDL commands (like CREATE, ALTER, DROP) deal with the structural schema of the database, such as creating or deleting tables. DML commands (like INSERT, UPDATE, DELETE) deal with the actual data inside those tables.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778645575802\"><strong class=\"schema-faq-question\"><strong>Is SELECT a DML or DQL command?<\/strong><\/strong> <p class=\"schema-faq-answer\">While older definitions sometimes group SELECT under DML, modern SQL standards classify SELECT strictly as a DQL (Data Query Language) command because it only retrieves data and does not manipulate or change it.<br><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778645576970\"><strong class=\"schema-faq-question\"><strong>Can I undo a TRUNCATE command?<\/strong><\/strong> <p class=\"schema-faq-answer\">In most relational database systems like MySQL and Oracle, TRUNCATE is an auto-committed DDL command and cannot be rolled back. However, in SQL Server, it can be rolled back if executed within an explicit transaction block.<br><\/p> <\/div> <\/div>\n\n\n\n<p><strong>Other SQL Resources:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-quiz\/\">SQL Quiz<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/\">SQL Exercise<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-operators\/\">SQL Operators with Examples<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-constraints\/\">SQL Constraints with Examples<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/hands-on-sql-projects\/\">SQL Projects Ideas for Beginners &amp; Beyond<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/\">SQL Interview Questions<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">SQL Queries to Practice Data Analysis<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Master all 5 types of SQL commands (DDL, DML, DQL, DCL, TCL). Get complete syntax, practical examples, and a SQL commands cheat sheet.<\/p>\n","protected":false},"author":41,"featured_media":117716,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36844],"content_type":[36252],"class_list":["post-92554","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-sql","content_type-tutorials"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Commands with Examples<\/title>\n<meta name=\"description\" content=\"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples\" \/>\n<meta property=\"og:description\" content=\"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-17T06:45:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-16T19:52:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1672\" \/>\n\t<meta property=\"og:image:height\" content=\"941\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples\",\"datePublished\":\"2024-04-17T06:45:35+00:00\",\"dateModified\":\"2025-05-16T19:52:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\"},\"wordCount\":1362,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png\",\"keywords\":[\"sql\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\",\"name\":\"SQL Commands with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png\",\"datePublished\":\"2024-04-17T06:45:35+00:00\",\"dateModified\":\"2025-05-16T19:52:49+00:00\",\"description\":\"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645514591\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645546962\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645575802\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645576970\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png\",\"width\":1672,\"height\":941,\"caption\":\"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645514591\",\"position\":1,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645514591\",\"name\":\"What are the 5 main types of SQL commands?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The five main types of SQL commands are DDL (Data Definition Language) for defining structures, DML (Data Manipulation Language) for managing data, DQL (Data Query Language) for retrieving data, DCL (Data Control Language) for managing permissions, and TCL (Transaction Control Language) for handling database transactions.<br>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645546962\",\"position\":2,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645546962\",\"name\":\"What is the difference between DDL and DML?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"DDL commands (like CREATE, ALTER, DROP) deal with the structural schema of the database, such as creating or deleting tables. DML commands (like INSERT, UPDATE, DELETE) deal with the actual data inside those tables.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645575802\",\"position\":3,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645575802\",\"name\":\"Is SELECT a DML or DQL command?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"While older definitions sometimes group SELECT under DML, modern SQL standards classify SELECT strictly as a DQL (Data Query Language) command because it only retrieves data and does not manipulate or change it.<br>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645576970\",\"position\":4,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#faq-question-1778645576970\",\"name\":\"Can I undo a TRUNCATE command?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In most relational database systems like MySQL and Oracle, TRUNCATE is an auto-committed DDL command and cannot be rolled back. However, in SQL Server, it can be rolled back if executed within an explicit transaction block.<br>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Commands with Examples","description":"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","og_locale":"en_US","og_type":"article","og_title":"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples","og_description":"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2024-04-17T06:45:35+00:00","article_modified_time":"2025-05-16T19:52:49+00:00","og_image":[{"width":1672,"height":941,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png","type":"image\/png"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples","datePublished":"2024-04-17T06:45:35+00:00","dateModified":"2025-05-16T19:52:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/"},"wordCount":1362,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png","keywords":["sql"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","name":"SQL Commands with Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png","datePublished":"2024-04-17T06:45:35+00:00","dateModified":"2025-05-16T19:52:49+00:00","description":"Learn about SQL commands, their types (DDL, DML, DQL, DCL, TCL), syntax, and examples for managing and manipulating relational databases effectively.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645514591"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645546962"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645575802"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645576970"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png","width":1672,"height":941,"caption":"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"SQL Commands (DDL, DML, DQL, DCL, TCL) with Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645514591","position":1,"url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645514591","name":"What are the 5 main types of SQL commands?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The five main types of SQL commands are DDL (Data Definition Language) for defining structures, DML (Data Manipulation Language) for managing data, DQL (Data Query Language) for retrieving data, DCL (Data Control Language) for managing permissions, and TCL (Transaction Control Language) for handling database transactions.<br>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645546962","position":2,"url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645546962","name":"What is the difference between DDL and DML?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"DDL commands (like CREATE, ALTER, DROP) deal with the structural schema of the database, such as creating or deleting tables. DML commands (like INSERT, UPDATE, DELETE) deal with the actual data inside those tables.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645575802","position":3,"url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645575802","name":"Is SELECT a DML or DQL command?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"While older definitions sometimes group SELECT under DML, modern SQL standards classify SELECT strictly as a DQL (Data Query Language) command because it only retrieves data and does not manipulate or change it.<br>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645576970","position":4,"url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#faq-question-1778645576970","name":"Can I undo a TRUNCATE command?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"In most relational database systems like MySQL and Oracle, TRUNCATE is an auto-committed DDL command and cannot be rolled back. However, in SQL Server, it can be rolled back if executed within an explicit transaction block.<br>","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png",1672,941,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-150x150.png",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-300x169.png",300,169,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-768x432.png",768,432,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-1024x576.png",1024,576,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-1536x864.png",1536,864,true],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1.png",1672,941,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-640x853.png",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-96x96.png",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2024\/04\/SQL-Commands-DDL-DML-DQL-DCL-TCL-with-Examples-1-150x84.png",150,84,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Master all 5 types of SQL commands (DDL, DML, DQL, DCL, TCL). Get complete syntax, practical examples, and a SQL commands cheat sheet.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/92554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=92554"}],"version-history":[{"count":79,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/92554\/revisions"}],"predecessor-version":[{"id":116652,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/92554\/revisions\/116652"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/117716"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=92554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=92554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=92554"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=92554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}