0% found this document useful (0 votes)
8 views31 pages

1692 Lab

The lab report details three experiments conducted in a Database Management System course, focusing on basic CRUD operations, aggregate functions, and JOIN operations. Each experiment outlines objectives, tasks performed, SQL queries used, and observations, demonstrating the student's proficiency in SQL and database management concepts. The report also includes mappings to course outcomes and complex engineering problems addressed through the lab activities.

Uploaded by

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

1692 Lab

The lab report details three experiments conducted in a Database Management System course, focusing on basic CRUD operations, aggregate functions, and JOIN operations. Each experiment outlines objectives, tasks performed, SQL queries used, and observations, demonstrating the student's proficiency in SQL and database management concepts. The report also includes mappings to course outcomes and complex engineering problems addressed through the lab activities.

Uploaded by

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

LAB REPORT

CSE312: Database Management System Lab

Topic:Basic CRUD Operations.

Submitted To
Ms. Rimi Akter (RIA)
Designation :Lecturer
Department of CSE,Daffodil International University

Submitted By
Student ID:02422220005101692

Section:63_L1
Student Name: Ankon Mazumder

Date of Assignment Submission: 9th December 2024


Department of CSE

Experimnent No: 01 Mapping:CO1 and CO2

Experiment Name Basic CRUD Operations.

Experiment Details:

Objective:
The primary objective of this lab was to perform basic CRUD (Create, Read, Update, Delete) operations in a
relational database system. This experiment helps understand how to interact with a database using SQL
queries, maintain data integrity, and manage records efficiently.

Key Learning Outcomes:


1. Develop proficiency in designing and working with database tables.
2. Learn to manipulate data effectively using SQL commands.
3. Gain practical experience in handling real-time database errors and debugging them.

Environment Setup:
Database Management System:[e.g.,MySQL,PostgreSQL]
· Tools:[e.g.,MySQL Workbench,pgAdmin,etc.]
·Operating System:[Insert OS Name]

Tasks Performed:
1. Create: Create a table named students with attributes id, name, email, and grade.
2. Read: Retrieve all records from the students table.
3. Update: Modify a specific student's grade.
4. Delete: Remove a record from the students table.

SQL Queries Used:


1. Create Table
SQL:

CREATE TABLE students(


id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100),
grade CHAR(2)
);

Daffodil International University


2. Insert Records
SQL:

INSERT INTO students (id, name, email, grade) VALUES


(1, 'John Doe', '[email protected]', 'A'),

(2,'Jane Smith','[email protected]', 'B');

3. Read Data
SQL:

SELECT*FROM students;

4. Update Data
SQL:

UPDATE students SETgrade =



A+ ′
WHRid = 2;

5. Delete Record
SQL:

DELETE FROM students WHERE id=1;

Obtained Output:

idn ame ema il grade

ohn Doe .doe@exam


Edit Copy Delete 1 J e.com A
john pl
ane Smith .smith@exa
Edit Copy Delete 2 J le.com B
jane mp
4.Record Updated Successfully

1 John [email protected] A

5. Record Deleted Successfully

2 Jane Smith [email protected] A+

Alternative Steps/Solution (If any):

If direct SQL execution fails, ensure:


1. Database connection is established correctly.
2. Proper permissions are granted for table creation and data manipulation.

Observation/Comments:

CRUD operations were successfully implemented, showing a clear understanding of SQL


fundamentals.
The exercise provided hands-on experience with database structure, command syntax, and query
troubleshooting.
Future focus will include optimizing queries and learning advanced operations like joins and
subqueries

Appendix A: Course Outcomes, Complex Engineering Problems (EP) and Complex Engineering Activities (EA)
Addressing.
Table: CSE312 Course Outcomes (COs) with Mappings
Complex Complex
Learning Knowledge Engineering
COs CO Statements POs Engineering
Domains Profile Problem Activities
The lab activity involves
performing CRUD
operations,which C2 K2
demonstrate a foundational A2 K3 EP1
CO1 PO1
understanding of database P2 K4 EP4
concepts like the relational K8
data model,normalization,and
SQL basics.

This activityinvolves optimizing and K2


C3 K3
designing relational databases EP1
CO2 PO3 A3 K4 EA3
through structured SQL
P3 K6
queries,fulfilling CO2 requirements. K8
Table: Addressing CO (1 to 3), Knowledge Profile (K),Attainment of Complex Engineering
Problems (EP):
SN EngineeringProblem Attain CO Justification
(EP) Definition Ment (with Knowledge Profile)

01 EP1:Depth of Yes/No CO1,CO2 Depth of knowledge is applied while


designing tables and performing CRUD
Knowledge
operations effectively.
required

03 EP4:Familiarity Yes CO1 Demonstrates familiarity with SQL


of Issues commands to manage and interact with
databases.

Table: Addressing CO's


SN COs Attainment Justification

01 CO1 Yes These Lab activities attain CO1 by.

02 CO2 Yes These Lab activities attain CO2 by.


LAB REPORT
CSE312: Database Management System Lab

Topic: Using Aggregate Functions (with LIMIT, BETWEEN,IN)

Submitted To
Ms.Rimi Akter (RIA)
Designation: Lecturer
Department of CSE,Daffodil International University

Submitted By

Student ID:02422220005101692

Section:63_L1
Student Name: Ankon Mazumder

Date of Assignment Distribution:27 November 2024


Department of CSE

Date of Assignment Submission: 13 December 2024

Experiment No: 02 Mapping: CO1 and CO2

Experiment Name: Using Aggregate Functions (with LIMIT, BETWEEN,IN)

Experiment Details:

Introduction:
Aggregate functions in SQL,such as SUMO,AVGO,COUNTO, MINO, and MAXO), are used to perform
calculations on a set of values and return a single value. Combining these functions with the clauses
LIMIT,BETWEEN,and IN enhances query flexibility and allows precise data analysis. This experiment
focuses on their practical usage in managing and querying a database.

Tools and Environment


·Database Management System: MySQL.
· SQL Query Editor: MySQL Workbench,phpMyAdmin.
·Dataset: A sample database containing tables such as Employees, Sales,or Products.

Procedure:
1. Setup the Database

CREATE TABLE Employees(


EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2),
JoiningDate DATE
);

INSERT INTO Employees (EmployeeID,Name, Department, Salary,JoiningDate)


VALUES
(1, 'Alice', 'HR', 5000.00, '2020-01-15'),
(2, 'Bob', 'Finance', 7000.00, '2019-03-20'),
(3, 'Charlie', 'IT', 6500.00,'2021-07-30'),
(4, 'David', 'IT', 8000.00, '2018-11-01'),
(5, 'Eve', 'HR', 4500.00, '2022-05-25');

Daffodil International University


Department of CSE

2.Using Aggregate Functions


a.SUMO with LIMIT
Query: Calculate the total salary of the top 3 highest-paid employees.

SELECT SUM(Salary) AS TotalSalary


FROM (SELECT Salary FROM Employees ORDER BY Salary DESC LIMIT 3) AS TopSalaries;

b.AVGO with BETWEEN


Query: Find the average salary of employees who joined between 2019 and 2021.

SELECT AVG(Salary) AS AverageSalary


FROM Employees
WHERE JoiningDate BETWEEN '2019-01-01' AND '2021-12-31';

c. COUNTO with IN
Query: Count the number of employees in the HR and IT departments.

SELECT COUNT(*) AS EmployeeCount


FROM Employees
WHERE Department IN ('HR', 'IT');

Obtained Output:

Daffodil International University


Alternative Steps/Solution (If any): NO alternative solution.

Daffodil International University


Department of CSE

Observation/Comments: Using these clauses efficiently can significantly reduce the amount of data
processed,making queries faster.

Demonstrate a comprehensive K2
understanding of fundamental K3
C2
database management concepts, K4 EP1
CO1 PO1 A2 EP4
including the relational data K8
P2
model,normalization
techniques,and SQL basics.
Design, implement and optimize
K2
relational databases,incorporating C3 K3 EP1
CO2 advanced SQL queries, indexing PO3 A3 K4 EP2 EA3
techniques and query optimization P3 K6 EP7
K8
strategies.

Understand and Analyze security


measures, distributed database
architectures and
C4
emerging trends in database EP4
CO3 PO5 A4 K6
management, demonstrating an P3
understanding of the broader
context and challenges in the field.

Table: Addressing CO (1 to 3), Knowledge Profile (K),Attainment of Complex Engineering


Problems (EP):
SN EngineeringProblem Attain CO Justification
(EP) Definition Ment (with Knowledge Profile)

01 EP1:Depth of Yes/No CO1,CO2


Knowledge
required

Daffodil International University


02 EP2:Range Yes/No CO2

Daffodil International University


Department of CSE

of Conflicting
Requirement S

03 EP4:Familiarity Yes/No CO1,CO3


of Issues

04 EP7: Yes/No CO2


Interdependence

Table: Addressing CO's


SN COs Attainment Justification

01 CO1 Yes/No These Lab activities attain CO1 by ..

02 CO2 Yes/No N/A

03 CO3 Yes/No These Lab activities attain CO3 by..

Daffodil International University


LAB REPORT
CSE312: Database Management System Lab

Topic: All JOIN Operations

Submitted To
Ms. Rimi Akter (RIA)
Designation Lecturer
Department of CSE,Daffodil International University

Submitted By
Student ID:02422220005101692

Section:63_L1
Student Name: Ankon Mazumder

Date of Assignment Distribution:27 November 2024


Department of CSE

Date of Assignment Submission: 13 December 2024

Experiment No: 03 Mapping:CO1 and CO2

Experiment Name All JOIN Operations

Experiment Details:

Introduction:
JOIN operations are fundamental to relational databases, enabling the combination of data from multiple
tables to produce insightful and comprehensive datasets. These operations are crucial in scenarios where data
is normalized and stored across different tables to minimize redundancy and improve database management.
Understanding and effectively utilizing JOINs can greatly enhance the ability to query,analyze, and present data
in a meaningful way.

Tools and Environment


·Database Management System: MySQL.
·SQL Query Editor: MySQL Workbench,phpMyAdmin.
·Dataset: A sample database containing tables such as Employees, Sales, or Products.

Procedure:
1. Setup the Database

CREATE TABLE Employees(


EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2),
JoiningDate DATE
);

INSERT INTO Employees (EmployeeID, Name, Department, Salary,JoiningDate)


VALUES
(1, 'Alice', 'HR', 5000.00, '2020-01-15'),
(2, 'Bob', 'Finance', 7000.00, '2019-03-20'),
(3, 'Charlie', 'IT', 6500.00, '2021-07-30'),
(4, 'David', 'IT', 8000.00, '2018-11-01'),
(5, 'Eve', 'HR', 4500.00, '2022-05-25');

Daffodil International University


Department of CSE

CREATE TABLE Departments (


DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);

INSERT INTO Departments (DepartmentID,DepartmentName)


VALUES
(1,'HR'),
(2, 'Finance'),
(3,'IT'),
(4,'Marketing');

2.All JOIN Operations

1.INNER JOIN
Query:This type returns rows that have matching values in both tables.

2.LEFT JOIN
Query:This type returns all rows from the left table and the matched rows from the right table. If no match
is found,NULL values are returned for columns from the right table.

SELECT e.EmployeeID,e.Name,d.DepartmentName
FROM Employees e
LEFT JOIN Departments d ON e.Department=d.DepartmentID;

3.RIGHT JOIN
Query: This type returns all rows from the right table and the matched rows from the left table. If no match
is found, NULL values are returned for columns from the left table.

SELECT e.EmployeeID,e.Name,d.DepartmentName
FROM Employees e
RIGHT JOIN Departments d ON e.Department=d.DepartmentID;

Daffodil International University


Department of CSE

4.FULL JOIN
Query: This type returns rows when there is a match in one of the tables. It returns all rows from the left table and from the right
table.

SELECT e.EmployeeID,e.Name,d.DepartmentName
FROM Employees e
FULL OUTER JOIN Departments d ON e.Department=d.DepartmentID;

Obtained Output:

1. 2. Desired
EmployeelD Name DepartmentName EmployeelD Name DepartmentName Output?
Alice HR 1 Alice NULL
Bob Finance 2 Bob NULL
Charlile IT
David IT 3 Charlie NULL
HR 4 David NULL

Eve
EmployeelD Name DepartmentName
3. YES

EmployeelD Name DepartmentName 1 Alice HR


NULL NULLHR 2 Bob Finance

NULL NULL Finance 3 charle IT


4 David IT
NULL NULL IT
5 Eve HR
NULL NULL Marketing NULL NULL Marketing

Alternative Steps/Solution (If any):

Observation/ Comments: Ideal for queries where you need to report or analyze data where the relationship between the tables is
mandatory

Daffodil International University


Department of CSE

Appendix A: Course Outcomes,Complex Engineering Problems (EP) and Complex Engineering Activities (EA)
Addressing.

Table: CSE312 Course Outcomes (COs) with Mappings


POs Complex Complex
COs CO Statements Learning Knowledge
Engineering Engineering
Domains Profile
Problem Activities
Demonstrate a comprehensive K2
understanding of fundamental K3
database management C2
K4 EP1
CO1 concepts,including the relational PO1 A2
K8 EP4
data model, normalization P2
techniques,and SQL basics.

Design, implement and optimize K2


relational databases,incorporating K3
C3 K4 EP1
CO2 advanced SQL queries, indexing PO3 A3 K6 EP2 EA3
techniques and query optimization P3 K8 EP7

strategies.

Understand and Analyze security


measures, distributed database
architectures and emerging trends C4
EP4
CO3 in database management, PO5 A4 K6
demonstrating an understanding of P3
the broader context and challenges
in the field.

Table: Addressing CO (1 to 3), Knowledge Profile (K), Attainment of Complex Engineering


Problems (EP):
SN EngineeringProblem Attain CO Justification
Ment
(EP) Definition (with Knowledge Profile)

01 EP1:Depth Yes/No CO1,CO2

Daffodil International University


Department of CSE

of Knowledge
required

EP2:Range of
02 Yes/No CO2
Conflicting
Requirement
S

03 EP4:Familiarity of Yes/No CO1,CO3


Issues

04 EP7:Interdependence Yes/No CO2

Table: Addressing CO's


SN COs Attainment Justification

01 CO1 Yes/No These Lab activities attain CO1 by..

02 CO2 Yes/No N/A

03 CO3 Yes/No These Lab activities attain CO3 by ..

Daffodil International University


LAB REPORT
CSE312:Database Management System Lab

Topic: Application of Stored Procedure, VIEW

Submitted To
Ms. Rimi Akter (RIA)
Designation Lecturer
Department of CSE,Daffodil International University

Submitted By
Student ID:02422220005101692

Section:63_L1
Student Name: Ankon Mazumder

Date of Assignment Distribution:27 November 2024


Date of Assignment Submission: 13 December 2024
Department of CSE

Experiment No: 04 Mapping:CO01 and CO2

Experiment Name Application of Stored Procedure, VIEW

Experiment Details:

Introduction:
Stored procedures are precompiled SQL statements that can be executed on demand. They are used to
encapsulate repetitive tasks, enforce business logic, and improve performance.

Views are virtual tables created by a query that joins and simplifies mnultiple tables into a single, easily
accessible structure. They do not store data themselves but provide a way to lookat data from one or more
tables.

Tools and Environment


·Database Management System: MySQL.
· SQL Query Editor: MySQL Workbench, phpMyAdmin.
·Dataset: A sample database containing tables such as Employees, Sales, or Products.

Procedure:
1. Setup the Database

CREATE TABLE Employees(


EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2),
JoiningDate DATE
);

INSERT INTO Employees (EmployeeID,Name,Department,Salary,JoiningDate)


VALUES
(1, 'Alice', 'HR', 5000.00, '2020-01-15'),
(2, 'Bob', 'Finance', 7000.00, '2019-03-20'),
(3, 'Charlie', 'IT', 6500.00, '2021-07-30'),
(4, 'David', 'IT', 8000.00, '2018-11-01'),
(5, 'Eve', 'HR', 4500.00, '2022-05-25');

Daffodil International University


Department of CSE

CREATE TABLE Departments(


DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);

INSERT INTO Departments (DepartmentID, DepartmentName)


VALUES
(1,'HR'),
(2,'Finance'),
(3,'IT'),
(4,'Marketing');

2.create stored procedure and view

1.stored procedure
Query: We'll create a stored procedure to retrieve employees' details by department.

CREATE PROCEDURE GetEmployeesbyDepartment(IN deptlane VARCHAPR(58))BEGTNI SELECT e.EmployeeID,e.lame,e.Salary,e.JoiningDate,d.Departnentlane FRONW Enployees e IMER JOIN Departments
d ON e.Department = d.Department ID WHERE d.Departmentlane= deptllame; ENO;

Executing the Stored Procedure:


To retrieve employees from the "IT" department, for example:

CALL GetEmployeesByDepartment('IT');

2.view
Query: We'll create a view to consolidate employee details with their department names.

CREATE VIEN EmployeeDetailsView AS SELECT e.EnployeeID, e.Name, e.Salary, e.JoiningDate, d.DepartmentNane FROM Employees e INMER JOIN Departments d ON
e.Department=d.DepartmentID;

Daffodil International University


Department of CSE

Querying the View:

SELECT*FROM EmployeeDetailsView;

Obtained Output:

1. 2.
EmployeelD Name Salary JoiningDate DepartmentName
Employeell Name SdbaryJimingDateDeparmentane 1 Alice 5000.00 2020-01-15 HR

2 Bob 7000.00 2019-03-20 Finance


3 Chatle 65000 2021-07-30 『
0 3 Charlie 6500.00 2021-07-30 IT
4 David 8000.00 2018-11-01 IT
4 David 80000 208-1-01
0 5 Eve 4500.00 2022-05-25 HR

Alternative Steps/Solution (If any):

Observation/Comments: Both views and stored procedures are powerful tools in SQL that provide different advantages
depending on the use case. Together, they help improve database management,performance,and security.

Daffodil International University


Department of CSE

Appendix A: Course Outcomes,Complex Engineering Problems (EP) and Complex Engineering Activities (EA)
Addressing.

Table: CSE312 Course Outcomes (COs) with Mappings

Complex Complex
Learning Knowledge
COs CO Statements POs Engineering Engineering
Domains Profile
Problem Activities
Demonstrate a comprehensive
understanding of fundamental K2
C2
database management K3 EP1
CO1 PO1 A2
concepts,including the relational K4 EP4
P2
data K8
model,normalization
techniques,and SQL basics.
Design, implement and optimize
K2
relational databases,incorporating C3 K3 EP1
CO2 advanced SQL queries, indexing PO3 A3 K4 EP2 EA3
techniques and query optimization P3 K6 EP7
K8
strategies.

Understand and Analyze security


measures,distributed database
architectures and emerging trends in C4
EP4
CO3 database management, PO5 A4 K6
demonstrating an understanding of P3
the broader context and challenges in
the field.

Table: Addressing CO (1 to 3), Knowledge Profile (K), Attainment of Complex Engineering


Problems (EP):
SN EngineeringProblem Attain CO Justification
(EP) Definition Ment (with Knowledge Profile)

01 EP1:Depth Yes/No CO1,CO2


of
Knowledge
required

02 EP2:Range of Yes/No CO2


Conflicting
Requirement

Daffodil International University


Department of CSE

03 EP4:Familiarity Yes/No CO1,CO3


of Issues

04 EP7: Yes/No CO2


Interdependence

Table: Addressing CO's


SN COs Attainment Justification

01 CO1 Yes/No These Lab activities attain CO1 by..

02 CO2 Yes/No N/A

03 CO3 Yes/No These Lab activities attain CO3 by..

Daffodil International University


LAB REPORT
CSE312: Database Management System Lab

Topic:Implementation of Trigger

Submitted To
Ms. Rimi Akter (RIA)
Designation:Lecturer
Department of CSE,Daffodil International University

Submitted By
Student ID:02422220005101692

Section:63_L1
Student Name: Ankon Mazumder

Date of Assignment Submission: 9th December 2024


Department of CSE

Experiment No: 05 Mapping:CO1 and CO2

Experiment Name Implementation of Trigger

Experiment Details:

Objective:

The primary objective of this lab was to perform basic CRUD (Create, Read, Update, Delete) operations in a relational
database system. This experiment helps understand how to interact with a database using SQL queries,maintain data
integrity, and manage records efficiently.
Key Learning Outcomes:

1. Develop proficiency in designing and working with database tables.


2. Learn to manipulate data effectively using SQL commands.
3. Gain practical experience in handling real-time database errors and debugging them.
Environment Setup:

·Database Management System: MySQL,PostgreSQL


·Tools:MySQL Workbench,pgAdmin
·Operating System: [Insert OS Name]
Tasks Performed:

1. Create: Create a table named students with attributes id, name, email, and grade.
2. Read: Retrieve all records from the students table.
3. Update: Modify a specific student's grade.
4. Delete: Remove a record from the students table.

SQL Queries Used:


1. Create Table
SQL:

CREATE TABLE AuditLog(


LogID INT AUTO INCREMENT PRIMARY KEY,
EmployeeID INT,
OldSalary DECIMAL(10,2),
NewSalary DECIMAL(10,2),
ChangeDate TIMESTAMP DEFAULT CURRENT TIMESTAMP
);

Daffodil International University


Create the Trigger
Query:We'll create a trigger that captures the old and new salaries whenever an update
occurs in the Employees table.

Example Usage
Suppose we update an employee's salary:

Obtained Output:
Alternative Steps/Solution (If any):

If direct SQL execution fails,ensure:


1. Database connection is established correctly.
2. Proper permissions are granted for table creation and data manipulation.

Observation/Comments:

Triggers are a powerful tool for automating database management tasks, enforcing business rules,and maintaining
data integrity. They provide a way to ensure that specific actions are taken in response to data changes, enhancing the
reliability and robustness of your database systems.

Appendix A: Course Outcomes, Complex Engineering Problems (EP) and Complex Engineering Activities (EA)
Addressing.

Table: CSE312 Course Outcomes (COs) with Mappings

Complex Complex
Learning Knowledge
COs CO Statements POs Engineering Engineering
Domains Profile
Problem Activities
The lab activity involves performing
CRUD operations,which demonstrate
K2
C2
a foundational understanding of K3 EP1
CO1 PO1 A2
database concepts like the relational K4 EP4
P2
K8
data model,normalization,and SQL
basics.
K2
This activityinvolves optimizing and
C3 K3
designing relational databases through K4 EP1
CO2 PO3 A3 EA3
structured SQL queries,fulfilling CO2 P3 K6
requirements. K8
Table: Addressing CO (1 to 3), Knowledge Profile (K),Attainment of Complex Engineering
Problems (EP):
SN EngineeringProblem Attain CO Justification
(EP) Definition Ment (with Knowledge Profile)

01 EP1:Depth of Yes/No CO1,CO2 Depth of knowledge is applied while


designing tables and performing CRUD
Knowledge
operations effectively.
required

03 EP4:Familiarity Yes CO1 Demonstrates familiarity with SQL


of Issues commands to manage and interact with
databases.

Table: Addressing CO's


SN COs Attainment Justification

01 CO1 Yes These Lab activities attain CO1 by.

02 CO2 Yes These Lab activities attain CO2 by.

You might also like