LAB 06
SQL : Data Manipulation Language (DML)
Topic: INSERT, UPDATE, DELETE
1. Objective:
By the end of this lab, you will be able to:
1. Understand the purpose of Data Manipulation Language (DML).
2. Differentiate between inserting, updating, and deleting records.
3. Insert a single record into a MySQL table.
4. Insert multiple records into a table.
5. Update existing records using the UPDATE statement.
6. Use the WHERE clause to identify specific records for modification.
7. Delete selected records using the DELETE statement.
8. Verify database changes using the SELECT statement.
9. Execute SQL commands in MySQL Workbench.
10. Understand the consequences of executing UPDATE or DELETE without a WHERE clause.
2. HARDWARE AND SOFTWARE REQUIRED:
Hardware
PC or laptop
Keyboard and mouse
Software
MySQL Server
MySQL Workbench
Windows, Linux, or macOS
Other requirements
Access to the university LMS
Lab manual and a folder for saving screenshots
Completion of introductory SQL labs, particularly database creation, table creation,
and basic SELECT queries
3. INTRODUCTION TO DML
3.1 What is SQL?
SQL stands for Structured Query Language. It is used to communicate with relational database systems.
Through SQL, users can create database structures, insert data, retrieve records, modify information, and remove records.
For example, a university database may contain student names, roll numbers, programs, and semesters. SQL allows the university
to add new students, correct existing information, or remove records when required.
3.2 What is DML?
DML stands for Data Manipulation Language.
DML commands are used to manipulate the data stored inside database tables.
In this lab, we will study three important DML commands:
1|Page
, DATABASE SYSTEMS LAB MANUAL
Command Purpose Real-life example
INSERT Adds new records Registering a new student
UPDATE Modifies existing records Correcting a student's semester
DELETE Removes existing records Removing a test record
Important distinction: These commands manipulate the records inside a table. They do not create the database or table structure
itself.
4. UNDERSTANDING THE PRACTICAL EXAMPLE
Throughout this lab, we will use a university student database.
Suppose a university maintains the following student information:
Student_ID Student_Name Program Semester
101 Ali BSCS 2
102 Sara BSAI 3
103 Ahmed BSSE 2
Each row represents one student, while each column represents a particular attribute of that student.
Our practical activities will demonstrate how to add, modify, and remove these records.
PRACTICAL ACTIVITIES:
Practical Activity 1: PREPARE THE DATABASE AND TABLE
Step 1: Open MySQL Workbench
Open MySQL Workbench and connect to your MySQL Server.
Step 2: Create or select the database
If you have already created UniversityDB in an earlier lab, execute:
USE UniversityDB;
If the database does not exist, create it first:
CREATE DATABASE UniversityDB;
USE UniversityDB;
Step 3: Create the Students table
Execute the following SQL statement:
CREATE TABLE Students (
Student_ID INT PRIMARY KEY,
Student_Name VARCHAR(50),
Program VARCHAR(30),
Semester INT
);
Understanding the code
CREATE TABLE Students creates a table named Students.
Student_ID INT stores an integer student ID.
Student_ID INT PRIMARY KEY makes the student ID unique and prevents duplicate or NULL
IDs.
Student_Name VARCHAR(50) stores a student's name.
Program VARCHAR(30) stores the program name.
Semester INT stores the semester number.
2|Page
, DATABASE SYSTEMS LAB MANUAL
If you created the table in a previous lab, do not run the same CREATE TABLE statement again. Use
the existing table.
Step 4: Verify the table
DESCRIBE Students;
Observe the table structure displayed in the output area.
Screenshot requirement: Capture the table structure in MySQL Workbench.
Practical Activity 2 : INSERT A SINGLE RECORD
What does INSERT do?
The INSERT statement adds a new record to a database table.
For example, when a new student registers at a university, their information must be added to the student
database.
Syntax
INSERT INTO table_name
(column1, column2, column3)
VALUES
(value1, value2, value3);
INSERT INTO specifies the target table.
The column list specifies where the data will be stored.
VALUES provides the actual data.
Activity:
Insert the following student into the Students table:
Student_ID Student_Name Program Semester
101 Ali BSCS 2
Execute:
3|Page