SQL Commands - DML, DDL, DCL, TCL, DQL With Query Example
SQL Commands - DML, DDL, DCL, TCL, DQL With Query Example
Query Example
Richard Peterson August 25, 2022
What is SQL?
SQL is a database language designed for the retrieval and management of data in a relational
database.
SQL is the standard language for database management. All the RDBMS systems like MySQL, MS
Access, Oracle, Sybase, Postgres, and SQL Server use SQL as their standard database language.
SQL programming language uses various commands for different operations. We will learn about
the like DCL, TCL, DQL, DDL and DML commands in SQL with examples.
In this SQL commands in DBMS tutorial, you will learn:
What is SQL?
Why Use SQL?
Brief History of SQL
Types of SQL
What is DDL?
What is Data Manipulation Language?
What is DCL?
What is TCL?
What is DQL?
Why Use SQL?
Here, are important reasons for using SQL
It helps users to access data in the RDBMS system.
It helps you to describe the data.
It allows you to define the data in a database and manipulate that specific data.
With the help of SQL commands in DBMS, you can create and drop databases and tables.
SQL offers you to use the function in a database, create a view, and stored procedure.
You can set permissions on tables, procedures, and views.
Brief History of SQL
Here, are important landmarks from the history of SQL:
1970 – Dr. Edgar F. “Ted” Codd described a relational model for databases.
1974 – Structured Query Language appeared.
1978 – IBM released a product called System/R.
1986 – IBM developed the prototype of a relational database, which is standardized by ANSI.
1989- First ever version launched of SQL
1999 – SQL 3 launched with features like triggers, object-orientation, etc.
SQL2003- window functions, XML-related features, etc.
SQL2006- Support for XML Query Language
SQL2011-improved support for temporal databases
Types of SQL
Here are five types of widely used SQL queries.
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Control Language(DCL)
Transaction Control Language(TCL)
Data Query Language (DQL)
Types of SQL
Let see each of them in detail:
What is DDL?
Data Definition Language helps you to define the database structure or schema. Let’s learn about
DDL commands with syntax.
Five types of DDL commands in SQL are:
CREATE
CREATE statements is used to define the database structure schema:
Syntax:
For example:
DROP
Drops commands remove tables and databases from RDBMS.
Syntax
DROP TABLE ;
For example:
ALTER
Alters command allows you to alter the structure of the database.
Syntax:
To add a new column in the table
For example:
TRUNCATE:
This command used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
Or
For example:
UPDATE:
This command is used to update or modify the value of a column in the table.
Syntax:
For example:
UPDATE students
WHERE StudID = 3;
DELETE:
This command is used to remove one or more rows from a table.
Syntax:
For example:
What is DCL?
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are useful to
give “rights & permissions.” Other permission controls parameters of the database system.
Examples of DCL commands:
Commands that come under DCL:
Grant
Revoke
Grant:
This command is use to give user access privileges to a database.
Syntax:
For example:
Revoke:
It is useful to back permissions from the user.
Syntax:
For example:
What is TCL?
Transaction control language or TCL commands deal with the transaction within the database.
Commit
This command is used to save all the transactions to the database.
Syntax:
Commit;
For example:
COMMIT;
Rollback
Rollback command allows you to undo transactions that have not already been saved to the
database.
Syntax:
ROLLBACK;
Example:
SAVEPOINT
This command helps you to sets a savepoint within a transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
Example:
SAVEPOINT RollNo;
What is DQL?
Data Query Language (DQL) is used to fetch the data from the database. It uses only one
command:
SELECT:
This command helps you to select the attribute based on the condition described by the WHERE
clause.
Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
For example:
SELECT FirstName
FROM Student
Summary:
SQL is a database language designed for the retrieval and management of data in a
relational database.
It helps users to access data in the RDBMS system
In the year 1974, the term Structured Query Language appeared
Five types of SQL queries are 1) Data Definition Language (DDL) 2) Data Manipulation
Language (DML) 3) Data Control Language(DCL) 4) Transaction Control Language(TCL) and,
5) Data Query Language (DQL)
Data Definition Language(DDL) helps you to define the database structure or schema.
Data Manipulation Language (DML) allows you to modify the database instance by inserting,
modifying, and deleting its data.
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are useful
to give “rights & permissions.”
Transaction control language or TCL commands deal with the transaction within the
database.
Data Query Language (DQL) is used to fetch the data from the database.