0% found this document useful (0 votes)
5 views

yash dbms

The document outlines a course on Database Management Systems (DBMS) for students in the School of Engineering and Sciences, detailing various experiments and lab exercises related to database concepts. It includes datasets for an online product system and a library borrowing system, along with SQL commands and queries for managing and analyzing data. Additionally, it covers topics like E-R modeling, relational data models, and DBMS architecture, providing a comprehensive overview of database management principles and practices.

Uploaded by

Yash Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

yash dbms

The document outlines a course on Database Management Systems (DBMS) for students in the School of Engineering and Sciences, detailing various experiments and lab exercises related to database concepts. It includes datasets for an online product system and a library borrowing system, along with SQL commands and queries for managing and analyzing data. Additionally, it covers topics like E-R modeling, relational data models, and DBMS architecture, providing a comprehensive overview of database management principles and practices.

Uploaded by

Yash Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 56

COURSE CODE- CAP2002L

INTRODUCTION TO DATABASE MANAGEMENT


SYSTEM

SCHOOL OF ENGINEERING AND SCIENCES (SOES)

SUBMITTED BY
Student Name Sagar
Enrollment Number 230160255012
Section/Group BCA (Machine Learning)
Semester III Semester – 2nd YEAR
Faculty Name Mr. Abhinav Sir

1
CSE2002L: Introduction to database management system

Session: 2024-2025

LIST OF EXPERIMENTS

S.No. Topic DATE SIGNATURE

Database Approach-Characteristics of Database


1.
Approach: Library and Product System
Database Management System (DBMS)
2. Operations

DBMS Environment, DBMS Functions and


3. Components

DBMS architecture and data independence


4.
E-R Modelling: Super classes, inheritance,
5.
specialization and generalization I
E-R Modelling: Super classes, inheritance,
6.
specialization and generalization II
Relational Data Mode, relational algebra I
7.
Relational Data Mode, relational algebra II
8.
Relational Algebra, Calculus &
9. Normalization

Relational database design: Functional


10. dependencies Database Security and
authorization I
Concurrency Control and Transaction
11. processing Database Security and
authorization II

2
LAB - 1

Title: Database Approach-Characteristics of Database Approach: Library


and Product System

SQL PRODUCT ONLINE SYSTEM DATASET:

It sounds like you’re looking for information or a dataset related to an online


product system for SQL. Typically, such a dataset might include tables and data
related to products, orders, customers, and other aspects of an e-commerce or
product management system. Here’s a basic structure for what such a dataset
might look like:

a) Customers Table

This table contains information about the customers who use the platform.
Each customer is assigned a unique customer ID.

• Customer: A unique identifier for each customer. Customer Name:


The name of the customer.
• Email: The customer’s email address.
• Phone: The customer’s phone number.
• Address: The customer's shipping address.
• Registration Date: The date the customer registered on the platform.

3
(Figure 1.1)

b) Products Table

This table contains details about the products that are available for purchase.

• Product ID: A unique identifier for each product.


• Product Name: The name of the product.
• Category: The category the product belongs to (e.g.,
Electronics, Clothing).
• Price: The price of the product.
• Stock Quantity: The number of units available in stock.

(Figure 1.2)

4
c) Orders Table

This table records the orders placed by customers.

• Order ID: A unique identifier for each order.


• Customer ID: The ID of the customer who placed the order (linked to the
Customers table).
• Product ID: The ID of the product that was ordered (linked to the
Products table).
• Quantity: The number of units of the product that were ordered.
• Order Date: The date the order was placed.
• Total Amount: The total cost of the order (calculated as Quantity *
Price).

5
(Figure 1.3)

2. Library Borrow Book System Dataset


This dataset simulates a library system where users can borrow books. It
contains three main tables: Users, Books, and Borrowed Books.

a) Users Table

This table contains information about users who borrow books from the
library.

• User ID: A unique identifier for each user. Username: The name of
the user.
• Email: The user’s email address.
• Phone: The user’s phone number.
• Membership Date: The date the user became a member of the library.

6
(Figure 1.4)

b) Books Table

This table stores information about the books available in the library.

• Book ID: A unique identifier for each book.


• Book Title: The title of the book.
• Author: The author of the book.
• Genre: The genre of the book (e.g., Fiction, Dystopian).
• Copies Available: The number of copies of the book available
for borrowing.

7
output

(Figure1.5)

c) Borrowed Books Table

This table records the books borrowed by users.

• Borrow ID: A unique identifier for each borrow transaction.


• User ID: The ID of the user who borrowed the book (linked to the Users
table).
• Book ID: The ID of the borrowed book (linked to the Books table).
• Borrow Date: The date the book was borrowed.
• Return Date: The date the book was returned (if it has been returned).
• Status: The status of the borrow (e.g., "Borrowed" or "Returned").

(Figure 1.6)

8
Key Differences Between the Two Datasets:

1. Purpose:
o The Product dataset is about purchasing products
online, focusing on customers, products, and orders.
o The library dataset focuses on borrowing books,
tracking users, available books, and borrowing
transactions.
2. Entities:
o Product system involves Customers, Products, and Orders. o
Library system involves Users, Books, and Borrowed Books.
3. Transactions:
o In Product, the key transaction is placing an order and
purchasing products. o In the library, the transaction
involves borrowing and returning books.

Both datasets provide a useful structure for different types of operations and
are designed to allow SQL queries that connect customers or users to the
items they interact with

9
LAB-2

TITLE: - Database Management System (DBMS) Operations

Create the tables (Employees, Departments, Projects, Employee_Projects)


CREATE TABLE Departments ( department_id INT PRIMARY KEY, department_name
VARCHAR(50) NOT NULL );
-- Insert data into Departments
INSERT INTO Departments (department_id, department_name) VALUES (1,
'HR'), (2, 'Sales'), (3, 'Engineering'), (4, 'Marketing');

(Figure 2.1)
-- Create the Employees table
CREATE TABLE Employees ( employee_id INT PRIMARY KEY, first_name
VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, department_id
INT, salary DECIMAL(10, 2), hire_date DATE, FOREIGN KEY (department_id)
REFERENCES Departments(department_id) );

-- Insert data into Employees


INSERT INTO Employees (employee_id, first_name, last_name, department_id,
salary, hire_date) VALUES (1, 'John', 'Doe', 1, 60000, '2021-05-10'), (2, 'Jane', 'Smith',
2, 75000, '2020-03-15'), (3, 'Bob', 'Johnson', 3, 80000, '2019-07-22'), (4,
'Alice', 'Davis', 4, 50000, '2018-01-10'), (5, 'Charlie', 'Brown', 2, 55000, '2021-11-
11');

10
(Figure 2.2)

-- Create the Projects table


CREATE TABLE Projects
( project_id INT PRIMARY KEY, project_name VARCHAR(100) NOT NULL,
start_date DATE, end_date DATE );
INSERT INTO Projects (project_id, project_name, start_date, end_date) VALUES
(1, 'Project A', '2021-01-01', '2021-12-31'), (2, 'Project B', '2022-01-01', NULL),
(3, 'Project C', '2020-05-01', '2022-05-01'), (4, 'Project D', '2021-06-01', '2021-1201');

Output:

(Figure 2.3)

11
-- Create the Employee_Tasks table
CREATE TABLE Employee_Tasks
( employee_id INT, task_id INT,

PRIMARY KEY (employee_id, task_id),


FOREIGN KEY (employee_id) REFERENCES Employees(employee_id),
FOREIGN KEY (task_id) REFERENCES Tasks(task_id)
);

-- Insert data into Employee_Tasks


INSERT INTO Employee_Tasks (employee_id, task_id)

(Figure 2.4)

12
SQL Commands and Questions

1. -- Retrieve all employees from the Employees table

(Figure 2.5)

2. -- Find the first name and last name of all employees with a salary
greater than 50000

(Figure 2.6)

13
3. -- List all departments along with their department names

(Figure 2.7)

4. -- Get the count of employees in each department

(Figure 2.8)

5. -- Find the average salary of employees in the "Sales" department

(Figure 2.9)

14
6. -- Retrieve employees who were hired in the year 2020

(Figure 2.10)

7. -- List the top 3 highest-paid employees

(Figure 2.11)

8. -- Find the employees who are not assigned to any project

15
(Figure 2.12)

9. -- Retrieve all projects that started after January 1, 2021

(Figure 2.13)

10.-- List all employees along with the total number of projects they are involved in

16
(Figure 2.14)

11.-- Get the names of employees working in the "HR" department

(Figure 2.15)

12.-- Find the department with the highest number of employees

(Figure 2.16)

13.-- List all employees along with their department names

17
(Figure 2.17)

14.-- Retrieve the details of employees who have the same salary as "John Doe"

(Figure 2.18)

15.---List all employees along with their department names.

(Figure 2.19)

18
19
LAB-3

TITLE: - DBMS Environment, DBMS Functions and Components

1. Get the total salary expenditure for each department.

(Figure 3.1)

2. Find the employees who have worked on more than 2 projects.

(Figure 3.2)

20
3. Retrieve the details of projects that have not ended yet.

(Figure 3.3)

4. List employees and their project names.

(Figure 3.4)

21
5. Find the project names that have more than 5 employees assigned.

(Figure 3.5)

6. Get the earliest hire date from the Employees table.

(Figure 3.6)

22
7. Retrieve employees who were hired in the last 6 months.

(Figure 3.7)

8. Find the names of employees who work on all projects.

( )

23
Figure 3.8
9. List the department names with no employees.

(Figure 3.9)

10. Retrieve the highest-paid employee in each department.

(Figure 3.10)

11. Find the total number of projects each department is handling.

( )

24
Figure 3.11
12. Get the list of projects along with the number of employees assigned to each.

(Figure 3.12)

13. Find the longest-running project.

(Figure 3.13)

14. List employees who have never worked on a project in their own department.

( )

25
Figure 3.14

( )

26
15. Retrieve the details of employees whose salary is within the top 10% of
their department.

(Figure 3.15)

16. List the names of employees who were hired in the same month they
were assigned their first project.

(Figure 3.16)

27
Lab - 4

TITLE: - DBMS architecture and data independence.

Creating table:

(Figure 4.1)

28
1. Additional Exercise 1: Logical Data Independence

(Figure 4.2)

Books:-

(Figure 4.3)

29
2. Additional Exercise 2: Logical Data Independence

(Figure 4.4)
Index activity

(Figure 4.5)

30
Lab-5

Title: - E-R Modelling: Super classes, inheritance, specialization and


generalization I

 In this activity, students will create a simple e-commerce database that


involves a Product superclass and its subclasses Book and Electronics. The
Product table will store common attributes, while each subclass will have
its specific attributes.

 Product table:

(Figure 5.1)
Output:

(Figure 5.2)

 Book table:

31
(Figure 5.3)
Output:

(Figure 5.4)

 Electronics table:

(Figure 5.5)
Output:

(Figure 5.6)

 Query to fetch all products with their specific details

32
(Figure 5.7)

 SQL code to create a cricket database with a focus on the unique event
of Yuvraj Singh hitting six sixes in an over.

 Players table:

33
(Figure 5.8)
Output:

(Figure 5.9)

 Matches table

34
Output: (Figure 5.10)

(Figure 5.11)
 Events table

Output: (Figure 5.12)

(Figure 5.13)

35
 Query to fetch match details along with the unique event

(Figure 5.14)

Output:

(Figure 5.15)

36
Brian Lara's Record-Breaking Innings

 Event: Brian Lara scored 400 not out against England in a Test match.
 Date: April 10-12, 2004
 Venue: Antigua Recreation Ground, St. John's, Antigua.

 Players table:

Output: (Figure 5.16)

(Figure 5.17)
 Matches table:

(Figure 5.18)

37
Output:

(Figure 5.19)

 Players table:

(Figure 5.20)

Output:

(Figure 5.21)

38
(Figure 5.22)

Output:

(Figure 5.23)

39
Lab-6

Title:- E-R Modelling: Super classes, inheritance, specialization and


generalization II

1. Superclasses, Inheritance, Specialization, and Generalization


 Superclasses and Subclasses: In E-R modeling, a superclass is a higher-
level entity that can have one or more subclasses inheriting attributes and
relationships. This approach helps create an organized structure for entities
that share common characteristics.
 Inheritance: Subclasses inherit attributes and relationships from their
superclass, similar to OOP. This reduces redundancy by grouping shared
characteristics in a superclass.
 Specialization: In specialization, a superclass is divided into subclasses
based on certain characteristics. For example, an "Employee" superclass
could be specialized into "Manager" and "Staff" subclasses.
 Generalization: This is the reverse process, where multiple subclasses are
generalized into a single superclass. For example, "Undergraduate" and
"Graduate" could be generalized into a "Student" superclass.

2. Relational Data Model and Relational Algebra (Part I and II)


 Relational Data Model: Defines data structures (tables) with rows (tuples)
and columns (attributes) to store and organize data. It also enforces data
integrity through primary keys, foreign keys, and constraints.
 Relational Algebra: A set of operations on relations (tables) to query data.
Common operations include:
o Selection (σ): Extracts rows that satisfy a condition.
o Projection (π): Selects specific columns from a table.
o Join: Combines rows from two tables based on a related column.
o Union (𝖴), Intersection (∩), and Difference (-): Perform set
operations on tables.

3. SQL Code Integrating E-R Modeling, Relational Algebra, and Explanation

Let's say we have an E-R model with the following tables: Employee (as a
superclass), Manager (specialization subclass), and Staff (specialization
subclass). Using SQL, we could perform relational operations and queries:

40
1.
CREATE TABLE Manager
( emp_id INT PRIMARY
KEY, department
VARCHAR(50),
FOREIGN KEY (emp_id) REFERENCES Employee(emp_id)
);
INSERT INTO Employee (emp_id, name, salary, job_type) VALUES (1, 'Alice', 75000,
'Manager');

(Figure 6.1)

2.
CREATE TABLE Manager
( emp_id INT PRIMARY KEY,
department VARCHAR(50),
FOREIGN KEY (emp_id) REFERENCES Employee(emp_id)
);
INSERT INTO Manager (emp_id, department) VALUES (1, 'Finance');

INSERT INTO Employee (emp_id, name, salary, job_type) VALUES (2, 'Bob', 50000, 'Staff');

41
(Figure 6.2)

3.
CREATE TABLE Staff (
emp_id INT PRIMARY
KEY, shift VARCHAR(10),
FOREIGN KEY (emp_id) REFERENCES Employee (emp_id)
);
INSERT INTO Employee (emp_id, name, salary, job_type) VALUES (2, 'Bob', 50000, 'Staff');
INSERT INTO Staff (emp_id, shift) VALUES (2, 'Day');

42
(Figure 6.3)

-- 3. Perform Relational Algebra-like Queries in SQL


-- a. Select all Managers (Specialization Example)
SELECT e.name, m.department
FROM Employee e JOIN Manager m ON e.emp_id = m.emp_id;

(Figure 6.4)
-- b. Join Employees and Managers for specific departments (Join Operation)
SELECT e.name, e.salary, m.department
FROM Employee e
JOIN Manager M ON e.emp_id = m.emp_id
WHERE m.department = 'Finance';

(Figure 6.5)

43
 Query all trucks in the Truck subclass
SELECT v.vehicle_id, v.brand, v.model, v.year,
t.payload_capacity FROM Vehicle v
JOIN Truck t ON v.vehicle_id = t.vehicle_id;

-- Query all motorcycles in the Motorcycle subclass


SELECT v.vehicle_id, v.brand, v.model, v.year,
m.engine_capacity FROM Vehicle v
JOIN Motorcycle m ON v.vehicle_id = m.vehicle_id;

(Figure 6.6)

(Figure 6.7)

44
Specialization
 Definition: Specialization is the process of defining one or more sub-entities
of a higher-level entity, allowing for more specific attributes or behaviors
for those sub-entities.
 Example: In your schema, the Manager and Staff tables represent
specialized roles within the broader Employee category. Managers may
have additional responsibilities and attributes not applicable to regular staff.
Inheritance
 Definition: Inheritance allows sub-entities to inherit attributes from a
parent entity, reducing redundancy and promoting consistency.
 Example: Both Manager and Staff tables inherit the emp_id, name,
and salary attributes from the Employee table. This means all
employees (regardless of role) share these fundamental attributes.
Generalization
 Definition: Generalization is the process of abstracting shared
characteristics from multiple sub-entities to form a more generic
entity.
 Example: Querying the Employee table provides a comprehensive view
of all employees, regardless of their specific roles. This allows for easy
reporting and analysis of general employee data. When you join the
Employee table with Manager or Staff, you can retrieve specialized details
while still leveraging the shared attributes defined in the Employee table.

45
Lab-7

Title:- Relational Data Model (Part I )

 Relational Data Model: Defines data structures (tables) with rows (tuples)
and columns (attributes) to store and organize data. It also enforces data
integrity through primary keys, foreign keys, and constraints.

2. SQL Code Integrating E-R Modeling, Relational Algebra, and Explanation

Let's say we have an E-R model with the following tables: Employee (as a
superclass), Manager (specialization subclass), and Staff (specialization
subclass). Using SQL, we could perform relational operations and queries:

Step 1: Create the Superclass and Subclass Tables

The relational data model defines the structure of the database. We begin by
creating the Employee superclass table, which holds the general employee
information, and two subclass tables, Manager and Staff, which inherit from
Employee. Each subclass holds specialized attributes unique to their type.

Sql

Copy code
-- Create Employee Table (Superclass)
CREATE TABLE Employee (
emp_id INT PRIMARY KEY, -- Unique employee ID
name VARCHAR(50), -- Employee's name
salary DECIMAL(10, 2), -- Employee's salary
job_type VARCHAR(10) -- Type of job (Manager or Staff)
);

-- Create Manager Table (Subclass of Employee)


CREATE TABLE Manager (
emp_id INT PRIMARY KEY, -- Unique employee ID (foreign key to
Employee)
department VARCHAR(50), -- Department the manager oversees
FOREIGN KEY (emp_id) REFERENCES Employee(emp_id)
);

46
-- Create Staff Table (Subclass of Employee)
CREATE TABLE Staff (
emp_id INT PRIMARY KEY, -- Unique employee ID (foreign key to
Employee)
shift VARCHAR(10), -- Shift the staff member works (e.g.,
Day, Night)
FOREIGN KEY (emp_id) REFERENCES Employee(emp_id)
);
Step 2: Insert Data into the Tables

Now, we insert some sample data into the Employee, Manager, and Staff tables to
simulate real-life employees.

sql
Copy code
-- Insert Employee data
-- Manager Alice in the Finance department
INSERT INTO Employee (emp_id, name, salary, job_type) VALUES (1, 'Alice',
75000, 'Manager');
INSERT INTO Manager (emp_id, department) VALUES (1, 'Finance');

-- Staff member Bob with a Day shift


INSERT INTO Employee (emp_id, name, salary, job_type) VALUES (2, 'Bob',
50000, 'Staff');
INSERT INTO Staff (emp_id, shift) VALUES (2, 'Day');

47
1. Employee Table:-

(Figure 7.1)

(Figure 7.2)

2. Manager Table:-

(Figure 7.3)

(Figure 7.4)

48
3. Staff Table:-

(Figure 7.5)

(Figure 7.6)

49
Lab-8

Tittle: - Relational Algebra-like Queries in SQL (part II)

Now let's write SQL queries that simulate relational algebra operations like
selection, projection, and join.

(a) Select all Managers (Specialization Example)

This query selects all employees who are managers and joins their information
from both the Employee and Manager tables.

SELECT e.name, m.department


FROM Employee e
JOIN Manager m ON e.emp_id = m.emp_id;
(b) Join Employees and Managers for a Specific Department

This query performs a join between the Employee and Manager tables, filtering
for employees who work in the 'Finance' department.

sql

SELECT e.name, e.salary, m.department


FROM Employee e
JOIN Manager m ON e.emp_id = m.emp_id
WHERE m.department = 'Finance';
(c) Generalized Query to Fetch All Employee Details

This query retrieves all employee details from the Employee table, regardless of
whether the employee is a manager or staff member.

sql

SELECT emp_id, name, salary, job_type


FROM Employee;

50
(Figure 7.1)

(Figure 7.2)

51
Lab-9

Title: - Relational Algebra Concepts and Operations


In this part, we will describe how to perform relational algebra operations using
SQL.

Relational Algebra Operations:

1. Selection (σ): Extracts rows that satisfy a condition.


o In SQL, we can use the WHERE clause to implement selection.

Example:

sql

-- Select employees who earn more than 60,000


SELECT * FROM Employee
WHERE salary > 60000;

(Figure 9.1)

52
2. Projection (π): Selects specific columns from a table.
o In SQL, this is done by simply listing the desired columns in
the SELECT statement.

Example:

sql

-- Select only the names and salaries of all employees


SELECT name, salary FROM Employee;

(Figure 9.2)

3. Join (𝔚): Combines rows from two or more tables based on a


related column.
o In SQL, this is performed using the JOIN clause.

53
Example:

sql

-- Join Employee and Manager tables to get all Manager details


SELECT e.name, e.salary, m.department
FROM Employee e
JOIN Manager m ON e.emp_id = m.emp_id;

(Figure 9.3)

4. Union (∪): Combines the results of two queries, removing duplicates.


o In SQL, this can be done using the UNION operator.

Example:

sql

-- Select names from both Employee (Managers) and Staff tables

54
SELECT name FROM Employee WHERE job_type = 'Manager'
UNION
SELECT name FROM Employee WHERE job_type = 'Staff';

(Figure 9.4)

5. Intersection (∩): Returns rows that appear in both result sets.


o In SQL, this can be done using the INTERSECT operator.

Example:

sql

-- Get employees who are both Managers and Staff (assuming they exist)
SELECT name FROM Employee WHERE job_type = 'Manager'
INTERSECT
SELECT name FROM Employee WHERE job_type = 'Staff';

55
6. Difference (-): Returns rows that are in the first result set but not in
the second.
o In SQL, this can be done using the EXCEPT operator.

Example:

sql

-- Get all employees who are Managers but not Staff


SELECT name FROM Employee WHERE job_type = 'Manager'
EXCEPT
SELECT name FROM Employee WHERE job_type = 'Staff';

 Both Difference and Intersection example:-

(Figure 9.5)

56

You might also like