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

DBMS lab manual final (1)

The document outlines a lab manual for a Database Management System course, detailing the design of an Entity-Relationship (ER) model for a university database. It includes requirements, entities, relationships, and SQL commands for creating tables related to students, professors, courses, and departments. Additionally, it covers various SQL operations, PL/SQL constructs, and schema design for a corporate environment, emphasizing integrity constraints and data organization.

Uploaded by

vimal.foruppo
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)
4 views

DBMS lab manual final (1)

The document outlines a lab manual for a Database Management System course, detailing the design of an Entity-Relationship (ER) model for a university database. It includes requirements, entities, relationships, and SQL commands for creating tables related to students, professors, courses, and departments. Additionally, it covers various SQL operations, PL/SQL constructs, and schema design for a corporate environment, emphasizing integrity constraints and data organization.

Uploaded by

vimal.foruppo
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/ 44

DATABASE MANAGEMENT SYSTEM

Lab Manuals

Submitted in partial fulfilment of the requirements for the award of


the degree of

Masters of Computer Application (MCA)


To

Guru Gobind Singh Indraprastha University, Delhi

Guide(s): Ms. Sushma Bahuguna Submitted by: Vimal Vajpeyi


Enrolment No.: 22317004424

Tecnia Institute of Advanced Studies, New Delhi - 110085


Batch (2024-2026)
1. Design the ER model for case study e.g. University Database.

Case Study: University Database


In DBMS, ER diagram for a university management system shows how the databases are connected to
each other. It also shows how all the databases are logically related to each other. We can also create
an ER diagram by drawing the figure of a different part of the university management systemand their
properties and how they perform their task.

Requirements:
1. The university has students enrolled in various courses.
2. Students belong to different departments.
3. The university employs professors to teach courses.
4. Each course is associated with a department.
5. Professors can teach multiple courses, and a course can be taught by multiple
professors.
6. Each student can enroll in multiple courses, and each course can have multiple
studentsenrolled.
7. Courses have grades assigned to students upon completion.
8. Professors also belong to departments.

Entities and Relationships:


1. Student (student_id, student_name, email, phone_number, date_of_birth,
department_id):
a) Each student is associated with one department.
b) A student can enroll in multiple courses.

2. Department (department_id, department_name):


a) Each department can have multiple students and multiple professors.

3. Professor (professor_id, professor_name, email, phone_number, department_id):


a) Professors belong to a department.
b) Professors can teach multiple courses.

4. Course (course_id, course_name, credits, department_id):


a) Each course is offered by a department.
b) Students can enroll in multiple courses, and professors can teach multiple
courses.

5. Enrollment (enrollment_id, student_id, course_id, grade):


a) This table links students and courses to represent student enrollment in
courses.

6. Teaches (teaches_id, professor_id, course_id):


a) This table links professors and courses to represent the courses professors
teach.
ER MODEL
ER Diagram with Commands:

1. Student Table:
CREATE TABLE Student (
student_id INT PRIMARY KEY, student_name VARCHAR(100),email VARCHAR(100),
phone_number
VARCHAR(15),
date_of_birth
DATE,
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id));

2. Department Table:
CREATE TABLE
Department (
department_id INT
PRIMARY KEY,
department_name
VARCHAR(100)
);

3. Professor Table:
CREATE TABLE Professor (
professor_id INT
PRIMARY KEY,
professor_name
VARCHAR(100),email
VARCHAR(100),
phone_number
VARCHAR(15),
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

4. Course Table:
CREATE TABLE Course (
course_id INT
PRIMARY KEY,
course_name
VARCHAR(100),
credits INT,
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);
5. Enrollment Table:
CREATE TABLE Enrollment (
enrollment_id INT
PRIMARY KEY,
student_id INT,
course_i
d INT,
grade
CHAR(2),
FOREIGN KEY (student_id) REFERENCES
Student(student_id),FOREIGN KEY (course_id)
REFERENCES Course(course_id)
);

6. Teaches Table:
CREATE TABLE Teaches (
teaches_id INT
PRIMARY KEY,
professor_id INT,
course_id INT,
FOREIGN KEY (professor_id) REFERENCES
Professor(professor_id),FOREIGN KEY (course_id)
REFERENCES Course(course_id)
);

ER Diagram Description:

 Student - Department Relationship: A student belongs to one department. This is represented


as a
Many-to-One relationship between Student and Department.

 Course - Department Relationship: Each course is offered by one department. This is


a Many-to-One relationship between Course and Department.

 Professor - Department Relationship: A professor belongs to one department, forming


a Many-to-One relationship between Professor and Department.

 Student - Course Relationship (Enrollment): A student can enroll in multiple courses,


and a course can have multiple students. This is a Many-to-Many relationship managed
by the Enrollment entity.

 Professor - Course Relationship (Teaches): A professor can teach multiple courses, and a
course can be taught by multiple professors. This is a Many-to-Many relationship
managed by the Teaches
entity.
2. Use of CREATE, INSERT statement and integrity constraints.
Create and insert records in the following tables:
1. Client_Master ( client_no, name, Primary_address, address2, city , state , pincode , bal_due )
2. Product_Master ( product_no , description, profit_percent, unit_measure, qty_on_hand,
recorder_lvl ,sell_price, cost_price )
3. Salesman_master(salesman_no , salesman_name, address1 ,address2 , city, pincode , state, sal_amt
,tgt_to_get, ytd_sales)
4. Sales_Order ( s_order_no, s_order_date, client_no, dely_addr, salesman_no, dely_type,
billed_yn,dely_date date, order_status)
5. Sales_Order_Details ( s_order_no, product_no, qty_ordered, qty_disp, product_rate)
6. Challan_Header ( challan_no, s_order_, challan_date, billed_yn )
7. Challan_Details ( challan_no, product_no, qty_disp )
3. Use of GROUP BY, LIKE statement

1. Find out the names of all clients.

2. Print the entire client_master table


3. Retrieve the list of names and the cities of all the clients

4. List the various products available from the product_master

5. Find the name of all clients having 'a' as the second letter in their names.
6. Find out the clients who stay in city whose second letter is 'a'.

7. Find the list of all clients who stay in Mumbai or city Delhi or city Madras.

8. List all the clients who are located in 'Bombay'.

9. Print the list of clients whose bal_due are greater than value 10000.
10. Print the information from sales_order table of order placed in month of january.

11. Display order information for client_no 'c001' and 'c002'.

12. Find the products with description as '1.44 drive' and '1.22 drive'.

13. Find the product whose selling price is more than 1500 and also find the new selling price as
original price * 15.

14. Rename the new in the above query as new_price


Not Done
15. Find the product whose cost price is less than 1500
16. List the product in sorted order of their.

17. Calculate the square root of price of each product.

18. Divide the cost of product '540 HDD' by difference between its price and 100
19. List the names,city,state of clients not in the state of 'Maharashtra' .

20. List the product_no,description,sell_price of products whose description begin with letter 'M'.

21. List of all orders that were canceled in month of March.


4. Use of AGGREGATE Operators
1. Count the total no. of orders.

2. Calculate the average price of all the products.

3. Calculate the minimum price of product

4. Determine the maximum and minimum product price. Rename the title as max_price and min_price
respectively.
5. Count the number of product having price greater than or equal to 1500.

6. Find all products whose qty_on_hand is less than recorder level.


5. Use of Joins & FUNCTIONS

1. Find out the product which has been sold to 'John Mathew'

2. Find out the product and their quantities that will have to delivered in the current month.

3. Find the product_no and description of moving products.


4. Find the names of the clients who have purchased 'CD Drive'.

5. List the product_no and s_order_no of customers having qty_ordered less than 5 from the
order detail Table for the product '8GB Pendrive'.

6. Find the products and their quantities for the orders placed by 'Tina' and 'William'.
6. Use of Date and Time Functions

1. Display the order no and day on which client placed their order.

2. Display s_order_date in the format "dd-month-yy" e.g 12-February-16.


3. Find the date,fifteen days after today’s date.

4. Find the no of days elapsed between today date and the delivery date of the orders placed by
the client.

5. Change the s_order_date of cllient_no'C001' to 24/07/16

6. Change the selling price of '1.44 Drive' to Rs. 1150.00

7. Delete the record with order no 'S0013' from the order table.

8. Delete all the records having delivery date before 2024-11-19.


9. Change the city of client_no 'C005' to 'Bombay' update client_master set city='Bombay'
where client_no='C005';

10. Change the delivery date of order no 'SO008' to 16-08-16.


7. View

1. Create a view from employee table consisting of few attributes from the table.
2. Create a view from department table taking few attributes of department table.
8. Use of PL/SQL Block constructs

1. Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 3 to
7. Store the radius and the corresponding values of calculated area in an empty table named
Areas.
2. Write a PL/SQL block to display whether the given number is Odd or Even.

3. Write a PL/SQL block with cursor ,showing the use of SQL%FOUND attribute
4. Write a PL/SQL block with cursor ,showing the use of SQL% ROWCOUNT, SQL% ISOPEN attribute.
9. Use of PL/SQL Functions and Procedures

1. Create a PL/SQL function to calculate power of a number


2. Create a PL/SQL function to reverse a number and print , i.e., if number is 145 then it should
print 541.
3. Create a PL/SQL procedure to demonstrate usage of procedures to calculate the net salary if
DA is 30% of basic, HRA is 10% of basic and TA is 7%. If basic salary is less than 7000, PF is 10%
and if basic salary between 7000 to 150000 then PF is 20%.
4. Create a PL/SQL procedure to calculate minimum of 3 numbers taken as input.
10. Use of PL/SQL Triggers

1. Consider the following Customer Schema: Id(Primary Key), Name, Age, Address, Salary Write a
PL/SQL row-level trigger for the customers table that would fire for INSERT or UPDATE or
DELETE operations to display the salary difference between the old values and new values.
2. Consider a Student Marksheet Database, in which student marks assessment of 20 students for
5 subjects is recorded. For this schema, create a trigger so that the total and average of
specified marks is automatically inserted whenever a new record is insert.
11. Use of PL/SQL Exception Handling

1. Write a PL/SQL program to implement exception handling for ZERO_DIVIDE


and NO_DATA_FOUND exceptions.
2. Write a PL/SQL program to implement user defined exception handling by taking user input for
age and checking if entered age is 100 to raise an exception.
12. Use of PL/SQL Users Creation

Write PL/SQL Code for creation and implementation of USERS with (grant and revoke) commands.
13. Implement a real-world problem by creating an efficient
schema, enforcing integrity contraints( This case study can be
further developed on any language in the upcoming semester)
 This schema is designed to model the relationship between employees, departments,
and projects in a corporate environment. The tables define the structure of data,
enforce integrity constraints, and lay the groundwork for future system expansion.

Tables and Purpose:-

1. Department Table
o Purpose: Stores information about various departments within the organization.
o Columns:
 dept_id (Primary Key): Unique identifier for each department.
 dept_name (VARCHAR): Name of the department.
 manager_id (VARCHAR): Identifier of the manager responsible for the department.
 location (VARCHAR): Location of the department.

2. Employee Table
o Purpose: Stores details about employees.
o Columns:
 emp_id (Primary Key): Unique identifier for each employee.
 first_name (VARCHAR): Employee's first name.
 last_name (VARCHAR): Employee's last name.
 email (VARCHAR): Email address of the employee.
 phone_number (BIGINT): Employee's phone number.
 hire_date (DATE): Date the employee was hired.
 job_title (VARCHAR): Employee's job designation.
 dept_id (Foreign Key): Links to the department the employee belongs to, referencing
Department(dept_id).
3. Projects Table
o Purpose: Stores information about projects undertaken by the organization.
o Columns:
 project_id (Primary Key): Unique identifier for each project.
 project_name (VARCHAR): Name of the project.
 start_date (DATE): The start date of the project.
 end_date (DATE): The end date of the project.
 budget (DECIMAL): The allocated budget for the project.
Key Features and Constraints

1. Primary Keys:

o Ensure unique identification of rows in all tables (dept_id, emp_id, project_id).

2. Foreign Key Relationships:

o Employee.dept_id references Department.dept_id, linking employees to their respective


departments.

3. NOT NULL Constraints:

o Enforced on critical columns like hire_date, job_title, start_date, end_date, and budget to
ensure essential data is always provided.

4. Data Types:

o Columns use appropriate data types for optimized storage and querying, such as BIGINT for
phone numbers and DECIMAL for budgets.

Advantages of This Schema

1. Relational Integrity:

o Foreign key relationships ensure consistency between related data in the Employee and
Department tables.

2. Extensibility:

o Additional tables (e.g., Employee_Project or Tasks) can be added without disrupting the
current design.

3. Clear Data Organization:

o Logical segregation of data into Departments, Employees, and Projects ensures clarity and
easier maintenance.

4. Enforces Business Rules:

o Integrity constraints like NOT NULL and foreign keys maintain data reliability and correctness.

You might also like