SQL | DDL, DQL, DML, DCL and TCL Commands - GeeksforGeeks (2024)

Improve

Looking for one place where you can find all the SQL commands or SQL sublanguage commands like DDL, DQL, DML, DCL, and TCL, then bookmark this article. In this write-up, you will explore all the Structured Query Language (SQL) commands with accurate syntax.

But before heading to the command section, let’s have a brief introduction to SQL.

Table of Content

  • Short Overview on SQL
  • DDL (Data Definition Language)
  • DQL (Data Query Language)
  • DML(Data Manipulation Language)
  • DCL (Data Control Language)
  • TCL (Transaction Control Language)

Short Overview on SQL

Structured Query Language (SQL), as we all know, is the database language by the use of which we can perform certain operations on the existing database, and also we can use this language to create a database. SQL uses certain commands like CREATE, DROP, INSERT, etc. to carry out the required tasks.

SQL commands are like instructions to a table. It is used to interact with the database with some operations. It is also used to perform specific tasks, functions, and queries of data. SQL can perform various tasks like creating a table, adding data to tables, dropping the table, modifying the table, set permission for users.

These SQL commands are mainly categorized into five categories:

  1. DDL – Data Definition Language
  2. DQL – Data Query Language
  3. DML – Data Manipulation Language
  4. DCL – Data Control Language
  5. TCL – Transaction Control Language

Now, we will see all of these in detail.

SQL | DDL, DQL, DML, DCL and TCL Commands - GeeksforGeeks (1)

DDL (Data Definition Language)

DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database. DDL is a set of SQL commands used to create, modify, and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application.

List of DDL commands:

  • CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure, and triggers).
  • DROP: This command is used to delete objects from the database.
  • ALTER: This is used to alter the structure of the database.
  • TRUNCATE: This is used to remove all records from a table, including all spaces allocated for the records are removed.
  • COMMENT: This is used to add comments to the data dictionary.
  • RENAME: This is used to rename an object existing in the database.

DQL (Data Query Language)

DQL statements are used for performing queries on the data within schema objects. The purpose of the DQL Command is to get some schema relation based on the query passed to it.We can define DQL as follows it is a component of SQL statement that allows getting data from the database and imposing order upon it. It includes the SELECT statement. This command allows getting the data out of the database to perform operations with it. When a SELECT is fired against a table or tables the result is compiled into a further temporary table, which is displayed or perhaps received by the program i.e. a front-end.

List of DQL:

  • SELECT: It is used to retrieve data from the database.

DML(Data Manipulation Language)

The SQL commands that deal with the manipulation of data present in the database belong to DML or Data Manipulation Language and this includes most of the SQL statements.It is the component of the SQL statement that controls access to data and to the database. Basically, DCL statements are grouped with DML statements.

List of DML commands:

  • INSERT: It is used to insert data into a table.
  • UPDATE: It is used to update existing data within a table.
  • DELETE: It is used to delete records from a database table.
  • LOCK: Table control concurrency.
  • CALL: Call a PL/SQL or JAVA subprogram.
  • EXPLAIN PLAN: It describes the access path to data.

DCL (Data Control Language)

DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system.

List of DCL commands:

GRANT: This command gives users access privileges to the database.

Syntax:

GRANTSELECT,UPDATEONMY_TABLETOSOME_USER,ANOTHER_USER;

REVOKE: This command withdraws the user’s access privileges given by using the GRANT command.

Syntax:

REVOKESELECT,UPDATEONMY_TABLEFROMUSER1,USER2;

TCL (Transaction Control Language)

Transactions group a set of tasks into a single execution unit. Each transaction begins with a specific task and ends when all the tasks in the group are successfully completed. If any of the tasks fail, the transaction fails. Therefore, a transaction has only two results: success or failure. You can explore more about transactions here. Hence, the following TCL commands are used to control the execution of a transaction:

BEGIN: Opens a Transaction.

COMMIT: Commits a Transaction.

Syntax:

COMMIT;

ROLLBACK: Rollbacks a transaction in case of any error occurs.

Syntax:

ROLLBACK;

SAVEPOINT: Sets a save point within a transaction.

Syntax:

SAVEPOINTSAVEPOINT_NAME;

Conclusion

If you are aware of SQL, then SQL commands are the foundation of an effective database management system. Whether you are manipulating data, or managing data, SQL provides all sets of tools. Now, with this detailed guide, we hope you have gained a deep understanding of SQL commands, their categories, and syntax with examples.



Last Updated : 27 Oct, 2023

Like Article

Save Article

Previous

SQL Operators

Next

SQL CREATE DATABASE Statement

Share your thoughts in the comments

Please Login to comment...

SQL | DDL, DQL, DML, DCL and TCL Commands - GeeksforGeeks (2024)

FAQs

What is DDL DML DCL TCL and Dql? ›

Based on functionalities performed by them, there are five types of SQL Commands- DDL(Data Definition Language), DML(Data Manipulation Language), DQL(Data Query Language), TCL(Transaction Control Language), DCL(Data Control Language).

What are the 5 types of SQL? ›

These SQL commands are mainly categorized into five categories:
  • DDL – Data Definition Language.
  • DQL – Data Query Language.
  • DML – Data Manipulation Language.
  • DCL – Data Control Language.
  • TCL – Transaction Control Language.
Aug 2, 2023

What are the 5 parts in SQL? ›

These SQL commands are essential to perform SQL operations and aid developers and database administrators in ensuring data consistency, integrity, and accessibility.
  • DDL or Data Definition Language. ...
  • DQL or Data Query Language. ...
  • DML or Data Manipulation Language. ...
  • DCL or Data Control Language.

What is the difference between DCL and TCL in SQL? ›

DCL in SQL stands for data control language and its commands are administrative powers that allow other users access to the database. TCL stands for transaction control language which commits, or saves, transactions done to the database or data.

What is difference between DDL DML and DCL in SQL? ›

DDL stands for Data Definition Language, which defines the structure or schema of the database. DML, or the Data Manipulation Language, helps us deal with managing and manipulating data in the database. DCL, or the Data Control Language, helps us deal with controls, rights, and permission in the database system.

What are the 4 major types of command types in SQL? ›

SQL. DDL, DQL, DML, DCL and TCL Commands - GeeksforGeeks.

Is truncate DDL or DML? ›

Although TRUNCATE TABLE is similar to DELETE , it is classified as a DDL statement rather than a DML statement. It differs from DELETE in the following ways: Truncate operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables.

What is the full form of TCL in SQL? ›

TCL stands for Transaction Control Languages. These commands are used for maintaining consistency of the database and for the management of transactions made by the DML commands. A Transaction is a set of SQL statements that are executed on the data stored in DBMS.

What is difference between SQL and MySQL? ›

SQL is a query programming language that manages RDBMS. MySQL is a relational database management system that uses SQL. SQL is primarily used to query and operate database systems. MySQL allows you to handle, store, modify and delete data and store data in an organized way.

What is trigger in SQL? ›

Answer: An SQL trigger is a database object that is associated with a table and automatically executes a set of SQL statements when a specific event occurs on that table. Triggers are used to enforce business rules, maintain data integrity, and automate certain actions within a database.

What is primary key in SQL? ›

The primary key in SQL is a single, or a group of fields or columns that can uniquely identify a row in a table. Putting it simply, it is a column that accepts unique values for each row.

What is rollback in SQL? ›

What is ROLLBACK in SQL? ROLLBACK is a transactional control language in SQL. It lets a user undo those transactions that aren't saved yet in the database. One can make use of this command if they wish to undo any changes or alterations since the execution of the last COMMIT.

What are the 8 keys in SQL? ›

Below is a description of each of these DBMS keys.
  • Primary key. A primary key is a column -- or a group of columns -- in a table that uniquely identifies the rows of data in that table. ...
  • Candidate key. ...
  • Super key. ...
  • Foreign key. ...
  • Alternate key. ...
  • Surrogate key. ...
  • Composite key. ...
  • Compound key.
Jun 27, 2022

What is difference between TRUNCATE and DELETE? ›

The delete statement is used to remove single or multiple records from an existing table depending on the specified condition. The truncate command removes the complete data from an existing table but not the table itself. It preserves the table structure or schema. It is a DML (Data Manipulation Language) command.

What is DDL DCL DML TCL commands? ›

Differentiating DDL, DML, DCL, TCL, and DQL Commands
CategoryFull FormCommon Commands
DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATE, RENAME
DMLData Manipulation LanguageSELECT, INSERT, UPDATE, DELETE
DCLData Control LanguageGRANT, REVOKE
TCLTransaction Control LanguageCOMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION
1 more row

What is DDL and TCL? ›

It is used to define data structures or overall database schema. It contains those commands, which are used to manage transactions within the database. 3. By using DDL commands, database transactions cannot be handled. TCL commands are meant to handle database transactions.

What are different types of commands in SQL? ›

SQL commands are broadly categorized into Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and Data Query Language (DQL), each serving distinct purposes.

What are Dql commands? ›

DQL is a portion of a SQL statement that allows you to get and organise data from a database. You can use the SELECT command to extract data from a database in order to perform actions on it. It is the same as the projection operation in relational algebra.

Top Articles
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5765

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.