Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
66 views27 pages

CSE312 - DBMS Lab Report Format 2

This lab report details the CSE312 Database Management System lab conducted by Deep Mitra, focusing on Data Manipulation Language (DML) operations using SQL. The report outlines objectives, tasks performed, and key concepts learned, including inserting, updating, deleting records, and advanced querying techniques. The hands-on experience aimed to enhance skills in managing and analyzing data within relational databases.

Uploaded by

deepmitra68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views27 pages

CSE312 - DBMS Lab Report Format 2

This lab report details the CSE312 Database Management System lab conducted by Deep Mitra, focusing on Data Manipulation Language (DML) operations using SQL. The report outlines objectives, tasks performed, and key concepts learned, including inserting, updating, deleting records, and advanced querying techniques. The hands-on experience aimed to enhance skills in managing and analyzing data within relational databases.

Uploaded by

deepmitra68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

LAB REPORT

CSE312: Database Management System Lab

Submitted To
Ms. Israt Jahan (IJN)
Designation:
Lecturer (Senior Scale)
Department of CSE, Daffodil International University

Submitted By

Student ID: 232-15-211


Section: 65_D2
Student Name: Deep Mitra
Table: CSE312 Course Outcomes (COs) with Mappings
Comp Compl
Lear lex ex
Knowl
PO ning Engin Engin
COs CO Statements edge
s Dom eering eering
Profile
ains Proble Activit
m ies
Demonstrate a comprehensive understanding of K2
C2
fundamental database management concepts, including PO K3 EP1
CO1 A2
the relational data model, normalization techniques, 1 K4 EP4
P2
and SQL basics. K8
Design, implement and optimize relational K2
databases, incorporating advanced SQL queries, C3 K3 EP1
PO
CO2 indexing techniques and query optimization A3 K4 EP2 EA3
3
strategies. P3 K6 EP7
K8
Understand and Analyze security measures,
distributed database architectures and emerging
C4
trends in database management, demonstrating an PO EP4
CO3 A4 K6
understanding of the broader context and 5
P3
challenges in the field.

Table: Lab Wise Activity List

Lab Class Proposed Activity CO


No.

Lab 1,2 Lab Setup and DDL (Create, Alter, Drop, Truncate) CO1

Lab 3,4,5 DML (Select, Insert, Update, Delete Operation) and CO2
Keys

Lab 6,7 Sub Query, Aggregate Function, Joining. Wildcards CO2


e.t.c

Lab 8,9 Union, Trigger, View, Stored Procedure e.t.c CO2

Lab 10 DCL (Grant, Revoke) and TCL (Commit, Savepoint CO2


and Rollback)

Lab 11 Complete Database Design and Analysis with few CO3

Daffodil International University


important Complex Query.

LAB REPORT

03
Topic: DML (Insert, Update, Delete, Select) and Advanced Querying (WHERE, ORDER BY,
GROUP BY, Aggregate Functions, Set Operations, Subqueries)

CO Mapping: Design, implement and optimize relational databases, incorporating advanced SQL
queries, indexing techniques and query optimization strategies.

Date of Assignment Distribution: 23June 2025


Date of Assignment Submission: 7 July 2025

Experiment No: 03 Experiment Name: Working with SQL Queries (DML


Operations)

Experiment Details:
In this experiment, we focused on performing Data Manipulation Language (DML) operations using
SQL. We worked with the deep` table to practice inserting, updating, deleting, and querying records. The
aim was to gain hands-on experience with essential SQL operations for managing data in relational
databases.

The tasks included:


 Creating and populating the `deep` table.
 Inserting multiple records into the table.
 Updating specific records using the `UPDATE` statement.
 Deleting records using the `DELETE` and `TRUNCATE` commands.
 Querying data using `SELECT` with `WHERE`, `ORDER BY`, and `GROUP BY` clauses.
 Using aggregate functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`).
 Performing set operations (`UNION`, `INTERSECT`, `EXCEPT`).

Daffodil International University


 Writing subqueries and nested queries.

Objective
 Learn how to insert, update, and delete records in a database table.
 Understand the use of WHERE, ORDER BY, and GROUP BY clauses for filtering and
sorting data.
 Gain practical skills in using aggregate functions to summarize data.
 Practice set operations to combine or compare query results.
 Demonstrate the use of subqueries for complex data retrieval.

What We Learned in This Lab


Basic DML Operations:

 INSERT: Adds new records to a table.


 UPDATE: Modifies existing records in a table.
 DELETE: Removes specific records from a table.
 TRUNCATE: Clears all records from a table while keeping the structure.

Querying Techniques:

 SELECT: Retrieves data from one or more tables.


 WHERE: Filters records based on specified conditions.
 ORDER BY: Sorts results in ascending (ASC) or descending (DESC) order.
 GROUP BY: Groups rows that have the same values into summary rows.

Aggregate Functions:

 COUNT(): Returns the number of rows.


 SUM(): Calculates the total of a numeric column.
 AVG(): Computes the average value.
 MIN(): Finds the smallest value.
 MAX(): Finds the largest value.

Advanced Operations:

 Set Operations:
o UNION: Combines results from multiple queries (removes duplicates)
o UNION ALL: Combines results (keeps duplicates)
o INTERSECT: Returns common rows between queries
o EXCEPT: Returns rows from first query not in second query
 Subqueries: Nested queries used within other SQL statements.

Pattern Matching:

 LIKE: Searches for a specified pattern:

Daffodil International University


o %: Matches any sequence of characters
o _: Matches any single character

Logical Operators:

 AND: Combines conditions where all must be true


 OR: Combines conditions where any can be true
 NOT: Negates a condition

Result Limiting:

 LIMIT: Restricts the number of rows returned


 OFFSET: Specifies where to start counting rows from

Note: In this lab, we focused primarily on practical applications of these operations using the
‘deep’ table, with special emphasis on the WHERE clause for filtering and GROUP BY for data
summarization.

Other Key Concepts:

 Aliases (AS): Provides temporary names for columns or tables


 Wildcards: Special characters used in pattern matching
 Comparison Operators: =, <>, >, <, >=, <=, BETWEEN
 IN: Specifies multiple possible values for a column

Daffodil International University


Creating Database and Table
Let's create a database named deep where we can store the following information about guests:

 ID (a unique identifier for each guest)


 First Name
 Last Name
 Email Address
 Registration Date (automatically recorded when a guest is added or updated)

Step 1: Create Database and Table

SQL Syntax:

Daffodil International University


Now run it by click on Go

Uses of Syntax:
 CREATE DATABASE: This command is used to create a new database in the SQL
environment.
 deep: The name of the database created for storing lab experiment data.
 USE deep: Sets the current working database to deep so that subsequent operations are
executed within it.
 CREATE TABLE: This command creates a new table within the selected database.
 deep: The name of the table created to store guest information.
 id INT(6) UNSIGNED: Declares a column named id with integer type (6-digit limit, no
negative values). Used to uniquely identify each guest.
 AUTO_INCREMENT: Automatically increases the value of the id field for each new
entry, ensuring uniqueness.
 PRIMARY KEY: Designates the id column as the primary key, meaning each value in
this column must be unique and not null.
 firstname VARCHAR(30): Declares a column for the guest's first name using the
VARCHAR data type, which stores variable-length character strings up to 30 characters.
 lastname VARCHAR(30): Declares a column for the guest's last name, also using
VARCHAR(30).
 email VARCHAR(50): Stores the email address of the guest as a variable-length string
up to 50 characters.
 reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP:
o Creates a column to store the date and time when a record is inserted or updated.
o DEFAULT CURRENT_TIMESTAMP sets the current date/time automatically during
insertion.

Daffodil International University


o ON UPDATE CURRENT_TIMESTAMP automatically updates the timestamp when the
record is modified.

Output:

Daffodil International University


Step 2: Inserting Records

SQL Syntax:

Uses of Syntax:

 INSERT INTO: Used to add new records into a table.


 deep: The name of the table where the data is being inserted.
 (firstname, lastname, email): Specifies the columns into which data will be inserted.
 VALUES ('John', 'Doe', '[email protected]'): Provides the values for each column in
the same order.

Daffodil International University


Output:

Daffodil International University


Step 3: Updating Records

SQL Syntax:

Uses of Syntax:

 UPDATE: Used to modify existing records in a table.


 deep: The table in which the update is performed.
 SET lastname = 'Abraham': Specifies the column to update and assigns a new value.
 WHERE id = 1: Filters the rows to update; only the record with id = 1 will be changed.

Output:

Daffodil International University


Daffodil International University
Step 4: Deleting Records

SQL Syntax:

Uses of Syntax:

 DELETE FROM deep: Removes one or more records from the deep table.
 WHERE id = 1: Ensures that only the record with id = 1 is deleted.
 TRUNCATE TABLE deep: Deletes all records from the table quickly without logging
individual row deletions.

Daffodil International University


Output:

Daffodil International University


Step 5: Querying Data

SQL Syntax:

Uses of Syntax

 SELECT *: Retrieves all columns from the table.


 FROM deep: Specifies the table to query.
 WHERE lastname = 'Abraham': Filters the results to include only rows where the
lastname is 'Abraham'.

Output:

Daffodil International University


Step 6: Sorting Data

SQL syntax:

Uses of Syntax

 SELECT id, firstname, lastname: Retrieves specific columns from the table.
 FROM deep: Specifies the table to select data from.
 ORDER BY lastname DESC: Sorts the result by lastname in descending order. Use ASC
for ascending order.

Daffodil International University


Output:

Daffodil International University


Step 7: Grouping Data

SQL Syntax:

Uses of Syntax

 SELECT COUNT(id) as Number: Uses the COUNT() aggregate function to count the
number of records, and aliases it as Number.
 lastname: Also selected so we can group by it.
 FROM deep: Specifies the source table.
 GROUP BY lastname: Groups the result set by the lastname field.

Output:

Daffodil International University


Step 8: Aggregate Functions

SQL Syntax:

Uses of Syntax

 SELECT AVG(amount_paid) as Average: Calculates the average value of the


amount_paid column and aliases the result as Average.
 FROM payments: Specifies the table where the data resides.

Other aggregate functions include:

 COUNT(column) – Counts number of rows


 SUM(column) – Calculates total
 MIN(column) – Finds smallest value
 MAX(column) – Finds largest value

Daffodil International University


Output:

Daffodil International University


Step 9: Set Operations

SQL Syntax:

Uses of Syntax

 SELECT firstname FROM deep WHERE lastname = 'Doe': Retrieves firstname values
where lastname is 'Doe'.
 UNION: Combines the results of two queries and removes duplicates.
 SELECT firstname FROM deep WHERE lastname = 'Hasan': Another query to get
firstname values for a different condition.

Other set operations:

 INTERSECT: Returns only rows present in both result sets.


 EXCEPT: Returns rows from the first query that are not in the second.

Daffodil International University


Output:

Daffodil International University


Step 10: Subqueries

SQL Syntax:

Uses of Syntax

 SELECT COUNT(id) as Number: Uses the COUNT() aggregate function to count the
number of records, and aliases it as Number.
 lastname: Also selected so we can group by it.
 FROM deep: Specifies the source table.
 GROUP BY lastname: Groups the result set by the lastname field.

Daffodil International University


Output:

Daffodil International University


Notepad Code:

Daffodil International University


Discussion

This experiment provided a comprehensive understanding of DML operations in SQL. By


working with the deep table, we practiced inserting, updating, and deleting records, as well as
querying data using various clauses and functions. The use of GROUP BY and aggregate
functions helped us summarize data efficiently, while set operations and subqueries allowed us to
perform complex data retrieval tasks. These skills are essential for managing and analyzing data
in real-world applications.

Conclusion
This lab enhanced our ability to manipulate and query data in relational databases using SQL. By
mastering DML operations, aggregate functions, and advanced querying techniques, we are better
prepared to handle data-driven tasks in fields like web development, data analysis, and software
engineering. The hands-on experience with phpMyAdmin and SQL commands has strengthened our
foundational knowledge of database management.

Obtained Output:

 Table deep created Desired


 Records inserted Output?
 Records updated
 Records deleted
 Data queried with WHERE
 Data sorted with ORDER BY
 Data grouped with GROUP BY
YES
 Aggregate functions applied
 Set operations performed
 Subqueries executed

Alternative Steps/Solution (If any):

Daffodil International University


 If phpMyAdmin is unavailable, use the MySQL Command Line Client or MySQL
Workbench.
 For complex queries, break them into smaller subqueries for debugging.
 Use aliases (AS) to improve query readability.

Observation/ Comments:
 The WHERE clause is powerful for filtering data but must be used carefully to avoid
unintended deletions or updates.
 ORDER BY and GROUP BY are essential for organizing and summarizing data.
 Aggregate functions provide quick insights into large datasets.
 Set operations and subqueries enable advanced data analysis but require precise syntax.
 Practicing these operations in phpMyAdmin builds confidence in database management.

Daffodil International University

You might also like