SQL Commands
SQL Commands
SQL Commands
Ashish Zope
Data Engineer at Bajaj Finserv
SQL Commands (DDL, DQL, DML, DCL and TCL)
➢ SQL commands are extensively used to interact with databases,
enabling users to perform a wide range of actions on database
systems.
SET
TRUNCATE
TRANSACTION
Data Definition Language (DDL)
➢ Definition:
DDL, or Data Definition Language, consists of SQL commands
used to define the database schema. It deals with
descriptions of the database schema and is used to create
and modify the structure of database objects in the database.
➢ Purpose:
DDL is a set of SQL commands used to create, modify, and
delete database structures, but not the data within them.
These commands are typically used by database
administrators and developers rather than general users, who
usually access the database through an application.
➢ Key DDL Commands:
CREATE, DROP, TRUNCATE and ALTER
Data Definition Language (DDL)
1. CREATE
Purpose: Used to create databases, tables, indexes, and views.
Syntax:
-- CREATE DATABASE
CREATE DATABASE database_name;
-- CREATE TABLE
CREATE TABLE table_name (
column1 datatype,
);
-- CREATE INDEXES
CREATE INDEX index_name ON table_name (column1, column2,
...);
-- CREATE VIEW
CREATE VIEW view_name AS
SELECT column1, column2, ... FROM table_name WHERE condition;
Data Definition Language (DDL)
2. ALTER
Purpose: Used to modify existing database objects like tables.
Syntax:
-- DROP DATABASE
DROP DATABASE database_name;
-- DROP TABLE
DROP TABLE table_name;
-- DROP VIEW
DROP VIEW view_name;
-- TO DROP INDEX
DROP INDEX index_name;
Data Definition Language (DDL)
4. TRUNCATE
Purpose: Used to delete all records from a table, but not the table itself.
Syntax:
-- DROP TRUNCATE
TRUNCATE TABLE table_name;
Data Manipulation Language (DML)
➢ Definition:
DML, or Data Manipulation Language, consists of SQL
commands used to manipulate data stored in a database. It
includes commands for inserting, updating, deleting, and
retrieving data.
➢ Purpose:
DML is used to manage data within database objects. These
commands allow users to perform operations such as adding
new records, modifying existing records, and removing
records.
➢ Definition:
DQL, or Data Query Language, consists of SQL commands
used to query and retrieve data from a database. It focuses on
the retrieval of data based on specific criteria.
➢ Purpose:
DQL is used to fetch data from the database. The primary
command in DQL is `SELECT`, which allows users to specify
the columns and conditions for data retrieval.
➢ Definition:
DCL, or Data Control Language, consists of SQL commands used
to control access to data in a database. It includes commands for
granting and revoking permissions to users and roles.
➢ Purpose:
DCL is used to manage access rights and permissions for database
users. These commands ensure that only authorized users can
perform certain actions on the database objects.
➢ Definition:
TCL, or Transaction Control Language, consists of SQL commands
used to manage transactions in a database. Transactions are
sequences of operations performed as a single logical unit of
work.
➢ Purpose:
TCL is used to ensure the integrity of data by managing the
changes made by DML statements. These commands help in
maintaining consistency and handling errors during data
manipulation.
If you find this helpful, Repost and follow for more content.
Submit corrections in comments, if any.