Data Manipulation Language (DML) in SQL – SELECT, INSERT, UPDATE, DELETE

Data Manipulation Language (DML) – SQL Tutorial

Data Manipulation Language (DML) is a part of SQL used to retrieve, insert, update, and delete data stored in database tables. Unlike DDL, DML works directly on the data, not on the structure.


1. SELECT Command

Definition: The SELECT command is used to retrieve data from one or more tables.

Purpose:

  • View records from a table
  • Filter required data
  • Display specific columns

Syntax:

SELECT column1, column2
FROM table_name;

Example:

SELECT name, email
FROM Student;

2. INSERT Command

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

Purpose:

  • Add single or multiple rows
  • Store new information

Syntax:

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

Example:

INSERT INTO Student (student_id, name, email, age)
VALUES (101, 'Rahim', 'rahim@gmail.com', 20);

3. UPDATE Command

Definition: The UPDATE command is used to modify existing records in a table.

Purpose:

  • Change existing data
  • Correct mistakes

Syntax:

UPDATE table_name
SET column = value
WHERE condition;

Example:

UPDATE Student
SET email = 'rahim123@gmail.com'
WHERE student_id = 101;

Note: Always use WHERE to avoid updating all rows.


4. DELETE Command

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

Purpose:

  • Delete specific rows
  • Clean unwanted data

Syntax:

DELETE FROM table_name
WHERE condition;

Example:

DELETE FROM Student
WHERE student_id = 101;

Warning: Without WHERE, all records will be deleted.


Difference Between DML Commands

Command Purpose Effect
SELECT Retrieve data Read only
INSERT Add data New rows added
UPDATE Modify data Existing rows changed
DELETE Remove data Rows deleted

Lab Practice Tasks

  1. Select all records from a table
  2. Insert at least 3 records
  3. Update one record using WHERE
  4. Delete one specific record

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন