Database Management Systems Lab Report
Database Management Systems Lab Report
UNIVERSITY
“JnanaSangama”, Belgaum – 590014, Karnataka
LAB REPORT
On
Submitted by
Shriram S Patil (1BM24CS278)
B. M. S COLLEGE OF ENGINEERING
(Autonomous Institution under VTU)
Bengaluru – 560019
Sep – 2025 to Jan – 2026
B. M. S COLLEGE OF ENGINEERING
Bull Temple Road, Bengaluru - 560019
(Affiliated to Visvesvaraya Technological University, Belgaum)
CERTIFICATE
This is to certify that the Lab work entitled “Database Management Systems
(23CS3PCDBM)” carried out by Shriram S Patil (1BM24CS278), who is bonafide
student of B. M. S. College of Engineering. It is in partial fulfilment for the award of
Bachelor of Engineering in Computer Science and Engineering of the Visvesvaraya
Technological University, Belgaum during the year 2025-26. The Lab report has been
approved as it satisfies the academic requirements in respect of a Database Management
Systems (23CS3PCDBM) work prescribed for the said degree.
The insurance database must maintain information about drivers, the cars they own, the
accidents reported, and the participation of each driver and car in those accidents. Each driver
in the system is uniquely identified by a driver ID, along with their name and address, and
each car is uniquely identified by its registration number together with details such as model
and manufacturing year. The system must allow storing ownership information that links a
driver to one or more cars, while also allowing a car to be linked to one or more drivers if
shared ownership occurs; duplicate ownership records for the same driver and car must not
exist. Accident information must be stored using a unique report number assigned to each
accident, along with the date on which the accident occurred and the location WHERE it
happened. Every accident reported in the system must have at least one participating driver
and car, and this participation is recorded by linking the driver, the involved car, and the
accident report together with the corresponding damage amount for that particular
involvement. A participation record must reference an existing driver, an existing car, and an
existing accident, and no two participation entries may repeat the same combination of driver,
car, and accident report. The database must ensure that damage amounts are non-negative,
accident dates are valid calendar dates, and car manufacturing years fall within reasonable
limits. It must also preserve referential integrity so that ownership or participation entries
cannot exist without valid driver, car, and accident information already present in the system.
Deletion policies must prevent removal of drivers or cars that appear in past accident
participation records unless historical consistency is preserved through controlled deletion
rules or archival mechanisms. The system should maintain accurate links between drivers,
cars, and accidents at all times, ensuring reliable retrieval of ownership histories, accident
histories, and damage information for administrative, legal, and insurance-related purposes.
1
Entity – Relationship Diagram:
2
Schema Diagram:
Create Database:
CREATE DATABASE insurance;
USE insurance;
Create Table:
CREATE TABLE person (
driver_id VARCHAR(10) PRIMARY KEY,
name VARCHAR(50),
address VARCHAR(100)
);
desc car;
desc accident;
desc owns;
4
desc participated;
5
(11, '2019-01-24', 'Mysore Road'),
(12, '2019-02-04', 'South End Circle'),
(13, '2019-01-21', 'Bull temple Road'),
(14, '2019-02-17', 'Mysore Road'),
(15, '2019-03-04', 'Kanakpura Road');
6
Queries:
1. Display all accidents.
2. Display driver id who did the accident damage greater than or equal to Rs.25000.
7
4. Show all accidents, drivers involved and damage amount.
7. Find cars owned by drivers but have not been involved in any accident
SELECT car.reg_num
8
FROM car
WHERE car.reg_num NOT IN (SELECT participated.reg_num FROM participated);
UPDATE participated
SET damage_amount = 25000
WHERE driver_id = ‘A05’;
SELECT * FROM participated;
9
11. Find drivers who caused maximum damage amount.
12. Create a view summarizing accidents with participants count and total damage.
10
Experiment 2: Bank Database
The banking system must store information about branches, bank accounts, customers,
deposit relationships, and loans so that branch details (identified by branch name together
with city and total assets) are linked to accounts and loans, each account (identified by an
account number) records the branch it belongs to and the current balance, customers are
recorded with their name, street and city, and a depositor relationship associates a customer
with an account; loans are recorded by a unique loan number together with the branch name
that issued the loan and the loan amount. Account numbers and loan numbers must be unique
identifiers, branch names are used to associate accounts and loans to a branch, and customer
names (as modelled) are used to identify customers referenced by depositor entries; every
depositor entry must reference an existing customer and an existing account so that
ownership and access relationships are always valid, and duplicate depositor records linking
the same customer and account are disallowed. The system must maintain referential integrity
so accounts cannot reference a non-existent branch, depositor rows cannot reference missing
customers or accounts, and loans must reference an existing branch; deletion of a branch,
account, or customer that is referenced by dependent records should be controlled (either
disallowed or handled by archival/controlled reassignment) to preserve historical transaction
and loan consistency. Numeric and temporal constraints must be enforced: account balances
should be constrained to valid values (for example non-negative WHERE overdraft is not
allowed), branch assets and loan amounts must be non-negative and within specified business
limits, and UPDATEs to balance or loan amounts should be auditable. Cardinality rules
implied by the schema are enforced: a branch may host many accounts and issue many loans,
an account belongs to exactly one branch, a customer may be linked to many accounts
through depositor relationships, and an account may have many depositors if joint accounts
are permitted by policy. Implementation must prevent orphaned records, ensure uniqueness
WHERE required, and rely on application logic or database-level triggers to enforce complex
rules such as cascading effects on deletion, business rules about allowed balance operations
or overdrafts, and any required validation when transferring accounts between branches or
when converting a customer’s identifying details; the database should thus reliably support
queries for branch-wise account lists, customer account ownership, account balances, and
loan portfolios while preserving historical and referential integrity for auditing and regulatory
reporting.
11
Entity – Relationship Diagram:
12
Schema Diagram:
1. Create the above tables by properly specifying the primary keys and the foreign keys.
2. Enter at least five tuples for each relation.
Create Database:
CREATE DATABASE bank;
USE bank;
Create Tables:
CREATE TABLE branch (
branch_name VARCHAR(20),
branch_city VARCHAR(20),
assets INT,
PRIMARY KEY (branch_name)
);
13
CREATE TABLE bankaccount (
acc_no INT,
branch_name VARCHAR(20),
balance INT,
PRIMARY KEY (acc_no),
FOREIGN KEY (branch_name) REFERENCES branch(branch_name) );
CREATE TABLE bankcustomer (
customer_name VARCHAR(20),
customer_street VARCHAR(20),
customer_city VARCHAR(20),
PRIMARY KEY (customer_name)
);
desc bankaccount;
desc bankcustomer;
14
desc depositer;
desc loan;
15
VALUES
('Avinash', 'Bull temple road', 'Bangalore'),
('Dinesh', 'Bannerghatta road', 'Bangalore'),
('Mohan', 'NationalCollege road', 'Bangalore'),
('Nikhil', 'Akbar road', 'Delhi'),
('Ravi', 'Prithviraj road', 'Delhi');
16
Queries:
1. Display the branch name and assets from all branches in lakhs of rupees and rename the
assets column to 'assets in lakhs'.
2. Find all the customers who have at least two accounts at the same branch.
3. Create a view which gives each branch the sum of the amount of all the loans at the
branch.
17
4. Find customers who have an account at all branches located in a specific city.
5. Find all customers who have an account and a loan at the Bangalore branch.
SELECT depositer.customer_name
FROM depositer, bankaccount, loan, branch
WHERE depositer.acc_no=bankaccount.acc_no AND
bankaccount.branch_name=branch.branch_name
AND branch.branch_name=loan.branch_name AND
branch.branch_city="Bangalore";
6. Find all branches that have greater assets than every branch in Bangalore.
SELECT branch_name
FROM branch
WHERE assets > ALL(SELECT assets FROM branch WHERE
branch_city="Bangalore");
18
DELETE FROM bankaccount
WHERE bankaccount.branch_name IN (SELECT branch_name FROM branch
WHERE branch_city="Delhi");
SELECT * FROM bankaccount;
UPDATE bankaccount
SET balance=balance+balance*0.05;
SELECT * FROM bankaccount;
19
Experiment 3: Employee Database
The employee database must record each employee’s identifying number, name, manager
reference, hire date, salary, and department affiliation while also tracking departmental
details, project assignments (including the role an employee plays on a project), and any
incentive payments given to employees. Every employee is represented by a unique
employee number and has a hire date and salary that must be valid; the manager field is a
self-referencing link that must, if present, point to an existing employee and must never
create a circular management chain or reference the employee themself. Departments are
identified by a unique department number and include a department name and location; every
department referenced by an employee or by other structures must exist in the department
table, and departments may contain zero or many employees. Projects are recorded with a
unique project number, project name and project location; employees may be assigned to
multiple projects and each project may have many employees, with each assignment carrying
the employee’s job role for that project — duplicate assignments of the same employee to the
same project are disallowed. Incentive payments are recorded with the employee reference,
the incentive date and the incentive amount; an incentive entry must reference an existing
employee and incentive amounts must be non-negative and dated on or after the employee’s
hire date. Referential integrity must be enforced so that employee records cannot reference
non-existent departments, projects, or managers, and assignment and incentive records cannot
exist without corresponding employee, project, or department records as appropriate. Salary,
incentive amounts, and any monetary fields must be constrained to valid numeric ranges and
hire/ incentive dates must be valid calendar dates (and typically not future-dated unless
business rules permit). Deletion and update policies must preserve historical consistency:
deleting an employee who appears as a manager, as a project assignee, or in incentive records
should be prevented or should be handled via controlled archival, reassignment, or soft-delete
flags rather than hard deletion to preserve audit trails; similarly, changing a department or
project identifier must either be disallowed if it would orphan historical records or handled by
introducing immutable surrogate keys. Business rules include preventing circular manager
chains, ensuring an employee’s manager (if specified) cannot be the employee themself,
disallowing duplicate project-assignments, requiring that incentive dates fall within the
employee’s employment window, and optionally requiring at least one project assignment or
at least one incentive record depending on policy for reporting. Implementation should use
primary-key and foreign-key constraints for identity and linkage, unique constraints to
prevent duplicate assignments, check constraints for monetary and date ranges, and
application logic or triggers for complex temporal or graph constraints (like cycle detection in
management relationships and enforcing non-overlap or other schedule-related rules if
assignments gain temporal attributes later). The system must therefore reliably support
queries such as employee reporting lines, department staffing lists, project rosters with job
20
roles, incentive payment histories, salary analyses, and audit reports while maintaining data
integrity, preventing inconsistent deletions, and preserving a complete historical record for
HR and compliance needs.
21
Schema Diagram:
EMPLOYEE (empno: int, ename: String, mgr_no: int, hiredate: Date, sal: int, deptno:
int)
1. Create the above tables by properly specifying the primary keys and the foreign keys.
2. Enter at least five tuples for each relation.
Create Database:
CREATE DATABASE employee;
USE employee;
Create Table:
CREATE TABLE project (
pno int PRIMARY KEY,
ploc varchar(20),
pname varchar(20)
);
22
CREATE TABLE employee (
empno int PRIMARY KEY,
ename varchar(20),
mgr_no int,
hiredate date,
sal int,
dept_no int,
FOREIGN KEY(dept_no) REFERENCES DEPT(dept_no)
);
desc dept;
desc assigned_to;
23
desc employee;
desc incentives;
24
INSERT INTO employee (empno, ename, mgr_no, hiredate, sal, dept_no) VALUES
(101, 'Raju', 101, '2013-03-04', 200000, 10),
(102, 'Ravi', 101, '2014-04-09', 95000, 10),
(103, 'Prasad', 101, '2015-07-09', 68000, 20),
(104, 'Mahesh', 101, '2016-02-04', 70400, 30),
(105, 'Ram', 101, '2015-10-10', 55300, 40);
25
Queries:
1. Retrieve the employee numbers of all employees who work on project located in
Bengaluru.
SELECT [Link]
FROM assigned_to a, employee e, project p
WHERE [Link] = [Link] AND [Link] = [Link] AND [Link] = 'Bengaluru';
SELECT [Link]
FROM employee e
WHERE [Link] NOT IN (SELECT [Link] FROM incentives i);
3. Write a SQL query to find the employees name, number, dept, job_role, department
location and project location who are working for a project location same as his/her
department location.
26
4. List employees with their department name and location.
27
7. Total incentives earned by each employee (lifetime).
10. Managers and their direct report counts (MGR_NO references EMPNO).
28
SELECT [Link] , [Link]
FROM assigned_to a , employee e
WHERE [Link]= [Link]
GROUP BY [Link]
HAVING COUNT([Link]) > 1;
29
Experiment 4: Supplier Database
30
Entity – Relationship Diagram:
31
Schema Diagram:
1. Create the above tables by properly specifying the primary keys and the foreign keys.
2. Enter at least five tuples for each relation.
Create Database:
CREATE DATABASE supplier;
USE supplier;
Create Table:
CREATE TABLE supplier (
sid INT PRIMARY KEY,
sname VARCHAR(100),
city VARCHAR(50)
);
32
);
desc parts;
desc catalog;
33
INSERT INTO catalog (sid, pid, cost) VALUES
(1, 103, 10.00),
(1, 101, 12.50),
(2, 101, 11.00),
(2, 104, 9.50),
(3, 102, 7.75),
(3, 105, 15.00),
(4, 103, 8.00),
(4, 104, 9.75);
34
Queries:
1. Find the pnames of parts for which there is some supplier.
SELECT [Link]
FROM parts p, supplier s, catalog c
WHERE [Link]=[Link] AND [Link]=[Link]
GROUP BY [Link];
SELECT [Link]
FROM supplier s, catalog c
WHERE [Link]=[Link]
GROUP BY [Link]
HAVING COUNT(DISTINCT [Link])=(SELECT COUNT(pid) FROM catalog);
SELECT [Link]
FROM supplier s,catalog c, parts p
WHERE [Link]=[Link] AND [Link]=[Link] AND [Link]= 'Red'
GROUP BY [Link];
35
4. Find the pnames of parts supplied by Acme Widget Suppliers and by no one else.
SELECT [Link]
FROM parts p, catalog c, supplier s
WHERE [Link]=[Link] AND [Link]=[Link] AND [Link]= 'Acme Widget Supplier';
5. Find the sids of suppliers who charge more for some part than the average cost of that
part (averaged over all the suppliers who supply that part).
SELECT [Link]
FROM supplier s, parts p, catalog c
WHERE [Link]=[Link] AND [Link]=[Link] AND [Link] > (SELECT AVG([Link]) FROM
catalog c WHERE [Link]=[Link] GROUP BY [Link]);
6. For each part, find the sname of the supplier who charges the most for that part.
36
Experiment 5: NoSQL Cloud Installation
(MongoDB Atlas)
Aim:
To install and configure a NoSQL database in the cloud using MongoDB Atlas and perform
basic database operations.
Software Requirements:
Web browser (Chrome / Firefox)
Internet connection
MongoDB Atlas account
Procedure:
1. Open a web browser and visit [Link]
2. Click on Sign Up and create a MongoDB Atlas account using email or Google login.
3. After successful login, create a new project.
4. Click on Build a Database and choose the Free Tier (M0) cluster.
5. Select the cloud provider and region (preferably nearest region).
6. Create the cluster and wait for deployment to complete.
7. Configure Database Access by creating a database user with username and password.
8. Configure Network Access by allowing access from the current IP address (or
[Link]/0).
9. Click Connect and obtain the MongoDB connection string.
10. Use MongoDB Compass or MongoDB Shell to connect to the cloud database using
the provided connection string.
11. Create a database and collections to perform operations such as insert, find, update,
and delete.
Result:
MongoDB Atlas cloud database was successfully created and connected. Basic NoSQL
operations were performed on the cloud-hosted database.
Conclusion:
Thus, a NoSQL database was successfully installed and configured in the cloud using
MongoDB Atlas, demonstrating cloud-based database deployment and access.
37
Experiment 6: NoSQL – Student Database
Create Database:
38
Queries:
1. Write a query to update EmailID of a student with RollNo 10.
Or
a) Open your Collections Table.
b) Click on Export Data -> Export Full Collection.
c) Export File Type → CSV.
d) A dialog box will open. Choose file destination and click save.
39
4. Drop the table.
5. Import a given a CSV dataset from your Local File System into MongoDB collection.
a) Open your collections table.
b) Click Add Data → Import JSON or CSV file.
c) Select previously saved CSV file ([Link]).
d) Click Import.
40
Experiment 7: NoSQL – Customer Database
Create Database:
41
Queries:
1. Write a query to display those records whose total account balance is greater than 1200 of
account type ‘Z’ for each Cust_id.
42
3. Export the created table into Local File System.
Or
e) Open your Collections Table.
f) Click on Export Data → Export Full Collection.
g) Export File Type → CSV.
h) A dialog box will open. Choose file destination and click save.
5. Import a given a CSV dataset from your Local File System into MongoDB collection.
a) Open your collections table.
b) Click Add Data → Import JSON or CSV file.
c) Select previously saved CSV file ([Link]).
d) Click Import.
43
Experiment 8: NoSQL – Restaurant Database
Create Database:
44
45
Queries:
1. Write a MongoDB query to display all the documents in the collection restaurants.
46
2. Write a MongoDB query to arrange the name of the restaurants in descending along with
all the columns.
47
3. Write a MongoDB query to find the restaurant Id, name, town and cuisine for those
restaurants which achieved a score which is not more than 10.
48
4. Write a MongoDB query to find the average score for each restaurant.
49
5. Write a MongoDB query to find the name and address of the restaurants that have a zip
code that starts with '10'.
50
Experiment 9: LeetCode Practice - I
Query:
Write a solution to find managers with at least five direct reports.
SELECT [Link]
FROM Employee e, Employee m
WHERE [Link] = [Link]
GROUP BY [Link]
HAVING COUNT([Link]) >= 5;
Input Output
51
Experiment 10: LeetCode Practice - II
Query:
Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all
policyholders who:
Have the same tiv_2015 value as one or more other policyholders, and
Are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute
pairs must be unique).
Round tiv_2016 to two decimal places.
52
AND tiv_2015 IN (
SELECT tiv_2015
FROM Insurance
GROUP BY tiv_2015
HAVING COUNT(*) > 1
);
Input Output
Output is 70 because the location constraint is checked irrespective of tiv_2015. The pid 3
and pid 5 have same lat, lat pair – 3,3. Hence pid 3 is excluded from the output. Final output
will only tiv_2016 from pid 1, 2 and 4 = 10 + 20 + 40 = 70.
53
Experiment 11: LeetCode Practice - III
Query:
Find all numbers that appear at least three times consecutively.
SELECT DISTINCT [Link] AS ConsecutiveNums
FROM Logs l1, Logs l2, Logs l3
WHERE [Link] = [Link] AND
[Link] = [Link] AND
[Link] = [Link] – 1 AND
[Link] = [Link] - 1;
54
Input
Output
55