In this blog, we have discuss different SQL components....

SQL Components

-----------------------------------------------------------------------------------------------------------

SQL (Structured Query Language) is used to create, manage, secure, and retrieve data from a database.

SQL is divided into 4 main components:

1.     DDL (Data Definition Language)

2.     DML (Data Manipulation Language)

3.     DCL (Data Control Language)

4.     DQL (Data Query Language)


1. DDL (Data Definition Language)

DDL is used to create and modify the structure of database objects such as tables, views, and indexes.

Simple Definition

DDL is used to create, change, or delete database structures.

Common Commands

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE
  • RENAME

Practical Example

Create a Table

CREATE TABLE Student

(

    StudentID NUMBER,

    StudentName VARCHAR2(30),

    City VARCHAR2(20)

);

Output

Table Created.


Add a New Column

ALTER TABLE Student

ADD Email VARCHAR2(50);


Delete the Table

DROP TABLE Student;


Real-Life Example

Think of building a new classroom.

  • Construct classroom → CREATE
  • Add windows → ALTER
  • Remove classroom → DROP

2. DML (Data Manipulation Language)

DML is used to insert, update, and delete data inside a table.

Simple Definition

DML changes the data stored in tables.

Common Commands

  • INSERT
  • UPDATE
  • DELETE

Practical Example

Insert Data

INSERT INTO Student VALUES(101,'Rahul','Ahmedabad');


Update Data

UPDATE Student

SET City='Surat'

WHERE StudentID=101;


Delete Data

DELETE FROM Student

WHERE StudentID=101;


Real-Life Example

Student admission office

  • New admission → INSERT
  • Change address → UPDATE
  • Cancel admission → DELETE

3. DCL (Data Control Language)

DCL is used to give or remove permissions from users.

Simple Definition

DCL controls who can access the database.

Common Commands

  • GRANT
  • REVOKE

Practical Example

Give Permission

GRANT SELECT

ON Student TO Rahul;

Rahul can now view the Student table.


Remove Permission

REVOKE SELECT

ON Student FROM Rahul;

Rahul can no longer view the Student table.


Real-Life Example

College Library

  • Give library card → GRANT
  • Cancel library card → REVOKE

4. DQL (Data Query Language)

DQL is used to retrieve data from the database.

Simple Definition

DQL is used to view or search data stored in tables.

Common Command

  • SELECT

Practical Example

View All Records

SELECT * FROM Student;


View Specific Columns

SELECT StudentName, City FROM Student;


Search Data

SELECT *

FROM Student

WHERE City='Ahmedabad';


Real-Life Example

Searching a student's result.

You are not changing anything.

You are only viewing the information.


Simple Database Example

Suppose we have this table:

Student Table

StudentID

Name

City

101

Rahul

Ahmedabad

102

Priya

Surat


DDL Example

CREATE TABLE Student(...);

Creates the table.


DML Example

INSERT INTO Student

VALUES(103,'Amit','Rajkot');

Adds a new student.


DQL Example

SELECT * FROM Student;

Displays all students.


DCL Example

GRANT SELECT

ON Student TO User1;

Allows User1 to view the table.


Difference Between DDL, DML, DCL and DQL

Feature

DDL

DML

DCL

DQL

Full Form

Data Definition Language

Data Manipulation Language

Data Control Language

Data Query Language

Purpose

Create or modify database structure

Insert, update, delete data

Manage user permissions

Retrieve data

Works On

Database objects (tables, views, indexes)

Data inside tables

Users and privileges

Data inside tables

Main Commands

CREATE, ALTER, DROP, TRUNCATE, RENAME

INSERT, UPDATE, DELETE

GRANT, REVOKE

SELECT

Changes Structure?

Yes

No

No

No

Changes Data?

No

Yes

No

No

Retrieves Data?

No

No

No

Yes

Security Related?

No

No

Yes

No


Memory Trick

Component

Easy Memory

DDL

Design the database (Create the structure)

DML

Manage the data (Insert, Update, Delete)

DCL

Control user access (Grant, Revoke)

DQL

Query the data (Select/View)


Summary

  • DDL → Defines the structure of the database (e.g., CREATE TABLE).
  • DML → Manipulates the data stored in tables (e.g., INSERT, UPDATE, DELETE).
  • DCL → Controls user permissions and security (e.g., GRANT, REVOKE).
  • DQL → Retrieves and displays data from the database (e.g., SELECT).

 

These four SQL components work together to build, manage, secure, and query a relational database effectively.


---------------------------------------------------------------------------------------------------------------

Or follow my blog from the below link


Also, Join my Youtube channel with the below link

Also, Join my Telegram channel with the below link

Also, join my Whatsapp group with the below link
https://chat.whatsapp.com/CCqyfPnot932cVcORhc3Vj