SQL Commands: DDL, DQL, DML, DCL and TCL With Examples (2024)

Last Updated : 29 Aug, 2024

Summarize

Comments

Improve

SQL commands are extensively used to interact with databases, enabling users to perform a wide range of actions on database systems. Understanding these commands is crucial for effectively managing and manipulating data.

This guide will introduce you to the various SQL sublanguage commands, including Data Definition Language (DDL), Data Query Language (DQL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL)

Here we covered all Important SQL commands, including their syntax and examples.

Table of Content

  • Short Overview of SQL
  • DDL (Data Definition Language)
  • DQL (Data Query Language)
  • DML (Data Manipulation Language)
  • DCL (Data Control Language)
  • TCL (Transaction Control Language)
  • Important SQL Commands
  • SQL Commands With Examples

But before heading to the SQL command section, let’s briefly introduce SQL.

Short Overview of SQL

Structured Query Language (SQL), as we all know, is the database language by which we can perform certain operations on the existing database, and we can also 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.

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

Lets see all of these in detail.

SQL Commands: DDL, DQL, DML, DCL and TCL With Examples (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:

Here are all the main DDL (Data Definition Language) commands along with their syntax:

CommandDescriptionSyntax
CREATECreate database or its objects (table, index, function, views, store procedure, and triggers)CREATE TABLE table_name (column1 data_type, column2 data_type, ...);
DROPDelete objects from the databaseDROP TABLE table_name;
ALTERAlter the structure of the databaseALTER TABLE table_name ADD COLUMN column_name data_type;
TRUNCATERemove all records from a table, including all spaces allocated for the records are removedTRUNCATE TABLE table_name;
COMMENTAdd comments to the data dictionaryCOMMENT 'comment_text' ON TABLE table_name;
RENAMERename an object existing in the databaseRENAME TABLE old_table_name TO new_table_name;

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.

DQL Command

There is only one DQL command in SQL i.e.

CommandDescriptionSyntax

SELECT

It is used to retrieve data from the database

SELECT column1, column2, ...FROM table_name WHERE condition;

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

Here are all the main DML (Data Manipulation Language) commands along with their syntax:

CommandDescriptionSyntax
INSERTInsert data into a tableINSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
UPDATEUpdate existing data within a tableUPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
DELETEDelete records from a database tableDELETE FROM table_name WHERE condition;
LOCKTable control concurrencyLOCK TABLE table_name IN lock_mode;
CALLCall a PL/SQL or JAVA subprogramCALL procedure_name(arguments);
EXPLAIN PLANDescribe the access path to dataEXPLAIN PLAN FOR SELECT * FROM table_name;

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:

Two important DCL commands and their syntax are:

CommandDescriptionSyntax
GRANTAssigns new privileges to a user account, allowing access to specific database objects, actions, or functions.GRANT privilege_type [(column_list)] ON [object_type] object_name TO user [WITH GRANT OPTION];
REVOKERemoves previously granted privileges from a user account, taking away their access to certain database objects or actions.REVOKE [GRANT OPTION FOR] privilege_type [(column_list)] ON [object_type] object_name FROM user [CASCADE];

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.

List of TCL Commands

Some TCL commands and their syntax are:

CommandDescriptionSyntax
BEGIN TRANSACTIONStarts a new transactionBEGIN TRANSACTION [transaction_name];
COMMITSaves all changes made during the transactionCOMMIT;
ROLLBACKUndoes all changes made during the transactionROLLBACK;
SAVEPOINTCreates a savepoint within the current transactionSAVEPOINT savepoint_name;

Important SQL Commands

Some of the most important SQL commands that you are likely to use frequently include:

  1. SELECT: Used to retrieve data from a database.
  2. INSERT: Used to add new data to a database.
  3. UPDATE: Used to modify existing data in a database.
  4. DELETE: Used to remove data from a database.
  5. CREATE TABLE: Used to create a new table in a database.
  6. ALTER TABLE: Used to modify the structure of an existing table.
  7. DROP TABLE: Used to delete an entire table from a database.
  8. WHERE: Used to filter rows based on a specified condition.
  9. ORDER BY: Used to sort the result set in ascending or descending order.
  10. JOIN: Used to combine rows from two or more tables based on a related column between them.

SQL Commands With Examples

The examples demonstrates how to use an SQL command. Here is the list of popular SQL commands with Examples.

SQL CommandExample
SELECTSELECT * FROM employees;
INSERTINSERT INTO employees (first_name, last_name, email) VALUES ('John', 'Doe', '[email protected]');
UPDATEUPDATE employees SET email = '[email protected]' WHERE first_name = 'Jane' AND last_name = 'Doe';
DELETEDELETE FROM employees WHERE employee_id = 123;
CREATE TABLECREATE TABLE employees ( employee_id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50));
ALTER TABLEALTER TABLE employees ADD COLUMN phone VARCHAR(20);
DROP TABLEDROP TABLE employees;
WHERESELECT * FROM employees WHERE department = 'Sales';
ORDER BYSELECT * FROM employees ORDER BY hire_date DESC;
JOINSELECT e.first_name, e.last_name, d.department_name FROM employees e JOIN departments d ON e.department_id = d.department_id;

Conclusion

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.



SQL Commands: DDL, DQL, DML, DCL and TCL With Examples (2)

GeeksforGeeks

SQL Commands: DDL, DQL, DML, DCL and TCL With Examples (3)

Improve

Previous Article

SQL Operators

Next Article

SQL CREATE DATABASE

Please Login to comment...

SQL Commands: DDL, DQL, DML, DCL and TCL With Examples (2024)
Top Articles
Weather for Pilots
New in 2022: Marine Corps loosens its strict tattoo policy
The Blackening Showtimes Near Century Aurora And Xd
Oldgamesshelf
123Movies Encanto
Kansas Craigslist Free Stuff
Jennette Mccurdy And Joe Tmz Photos
Seething Storm 5E
Is Csl Plasma Open On 4Th Of July
Kris Carolla Obituary
Www.megaredrewards.com
Concacaf Wiki
Canelo Vs Ryder Directv
Bustle Daily Horoscope
Pollen Count Central Islip
Nitti Sanitation Holiday Schedule
Becu Turbotax Discount Code
Apus.edu Login
Vermont Craigs List
Paychex Pricing And Fees (2024 Guide)
R Cwbt
Amazing deals for DKoldies on Goodshop!
Cta Bus Tracker 77
Energy Healing Conference Utah
How To Level Up Roc Rlcraft
The BEST Soft and Chewy Sugar Cookie Recipe
Ford F-350 Models Trim Levels and Packages
Mj Nails Derby Ct
Which Sentence is Punctuated Correctly?
Student Portal Stvt
Claio Rotisserie Menu
new haven free stuff - craigslist
Where Do They Sell Menudo Near Me
Http://N14.Ultipro.com
Exploring The Whimsical World Of JellybeansBrains Only
Family Fare Ad Allendale Mi
Nobodyhome.tv Reddit
Wrigley Rooftops Promo Code
Doordash Promo Code Generator
Electric Toothbrush Feature Crossword
Pink Runtz Strain, The Ultimate Guide
Content Page
Embry Riddle Prescott Academic Calendar
Theater X Orange Heights Florida
Dagelijkse hooikoortsradar: deze pollen zitten nu in de lucht
Phone Store On 91St Brown Deer
Www Pig11 Net
York Racecourse | Racecourses.net
Brutus Bites Back Answer Key
Thrift Stores In Burlingame Ca
When Is The First Cold Front In Florida 2022
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 5694

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.