DML (Data Manipulation Language) in SQL

Introduction

After learning how to create and manage database structure using DDL, the next step is working with the actual data stored inside tables.

This is where Data Manipulation Language (DML) comes in.

DML includes SQL commands used to insert, retrieve, update, and delete data in a database.

These commands are used regularly in real-world applications because they handle day-to-day database operations.


What is DML

Data Manipulation Language (DML) is a set of SQL commands used to interact with the data stored in database tables.

While DDL defines the structure of the database, DML focuses on managing the data inside that structure.


Common DML Commands

The most commonly used DML commands are:

  • SELECT

  • INSERT

  • UPDATE

  • DELETE

Each command serves a different purpose.


SELECT Command

The SELECT command is used to retrieve data from a table.

It is one of the most frequently used SQL commands.

Example:

SELECT * FROM Students; 

This query returns all records from the Students table.

You can also retrieve specific columns:

SELECT name, age FROM Students; 

INSERT Command

The INSERT command is used to add new records to a table.

Example:

INSERT INTO Students (id, name, age) VALUES (1, 'Rahul', 20); 

This adds a new row to the Students table.


UPDATE Command

The UPDATE command is used to modify existing records.

Example:

UPDATE Students SET age = 21 WHERE id = 1; 

This updates the age of the student with id = 1.

Important:
Always use the WHERE clause to avoid updating all records unintentionally.


DELETE Command

The DELETE command is used to remove records from a table.

Example:

DELETE FROM Students WHERE id = 1; 

This deletes the record where id = 1.

If you do not use WHERE:

DELETE FROM Students; 

It will delete all records from the table.


Characteristics of DML Commands

DML commands have the following characteristics:

  • They operate on data inside tables

  • They are used for data manipulation

  • Changes can be controlled using transactions (COMMIT, ROLLBACK)

  • They are used frequently in applications and APIs


Example Scenario

In a student management system, DML commands are used to:

  • Add new students (INSERT)

  • View student details (SELECT)

  • Update student information (UPDATE)

  • Remove student records (DELETE)

These operations happen regularly in real-world applications.


Key Points to Remember

  • DML stands for Data Manipulation Language

  • It is used to work with data inside tables

  • Common commands are SELECT, INSERT, UPDATE, and DELETE

  • These commands are used in almost every database application

Understanding DML is important because it allows you to interact with and manage data effectively.