DBMS lab manual final (1)
DBMS lab manual final (1)
Lab Manuals
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.
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:
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
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.
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.
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.
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'.
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.
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.
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.
4. Find the no of days elapsed between today date and the delivery date of the orders placed by
the client.
7. Delete the record with order no 'S0013' from the order table.
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. 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
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.
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 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.
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.
o Logical segregation of data into Departments, Employees, and Projects ensures clarity and
easier maintenance.
o Integrity constraints like NOT NULL and foreign keys maintain data reliability and correctness.