0% found this document useful (0 votes)
178 views22 pages

DBMS Lab - Manual Dec 15, 2020

The document provides details of experiments to be performed on database systems, including installing database software, creating tables and inserting data, implementing various types of joins, and creating a university database schema. Experiments cover skills like installing MySQL and Oracle, defining schemas for vehicles, students, and projects, adding constraints, and writing SQL queries to retrieve and update data. Overall, the experiments aim to teach core database concepts through hands-on practice with database management systems.

Uploaded by

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

DBMS Lab - Manual Dec 15, 2020

The document provides details of experiments to be performed on database systems, including installing database software, creating tables and inserting data, implementing various types of joins, and creating a university database schema. Experiments cover skills like installing MySQL and Oracle, defining schemas for vehicles, students, and projects, adding constraints, and writing SQL queries to retrieve and update data. Overall, the experiments aim to teach core database concepts through hands-on practice with database management systems.

Uploaded by

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

Database Systems (CSPE-25 and ITPC-25)

List of Experiments

Experiment No.- 01
Focus: To learn installation.

Installation of MYSQL/ ORACLE (Refer Video Tutorial)


http://www.spoken-tutorial.org/
Show Video from link http://www.spoken-tutorial.org/keyword-search/?q=SQL
PostgreSQL Spoken Tutorial link
https://spoken-tutorial.org/tutorial-search/?
search_foss=RDBMS+PostgreSQL&search_language=English

Experiment No.- 02

Focus: Create tables and insert tuples.

Create tables and insert tuples in the databases described by the following relational schemas.

a) CAR (Registration-No, Chassis-No, Engine-No, Company-Name, Model, Year-Model, Price)


PERSON ( Aadhar-No, Name, Address, City)
OWN-BY (Registration-No, Aadhar-No)
DRIVER (License-No., Date-of-Issue, Valid-up-to, Aadhar-No.)

b) STUDENT (Roll-No., Name, Father-Name, Mother-Name, City, Dept-Code)


DEPARTMENT (Dept-Code, Dept-Name, Dept-Head)
PROGRAM (Degree-Name, Discipline-Name)
ENROLLED (Roll-No., Degree-Name)

c) COMPANY (C-Registration-No, C-Name, Address)


PERSON ( Aadhar-No, Name, Father-Name, Date-of-Birth, Address)
OWNED-BY (C-Registration-No, Aadhar-No)

d) BOOK (Access-No., Title, Author, Subject-Code)


MEMBER (Membership-No., Type)
EMPLOYEE (Emp-Code, Name, Designation, Dept-Name)
STUDENT (Roll-No., Dept-Name, Program)
BOOKS-ISSUE (Register-Entry-No., Access-No., Membership-No., Date-of-Issue)
BOOKS-RETURN (Access-No., Return-Date, Comment)

1
Experiment No.- 03

Focus Area: Tables and various Key Constraints

In Computer Engineering department, projects are assigned to the students. Design a database to
maintain data related to the students, projects, guides and project assigned to different groups of
the students. The explanation of the scenario is as under:

A group of the students has minimum three students; however, a group can also have four
students with the prior permission of the HOD. The teachers have their different subject areas in
which they prefer to guide projects. A teacher can supervise maximum three projects in a
semester. Consider appropriate attribute types for entity/relation types keeping in view
terminology used in the department.

Create a database for the following relational schema and insert tuples.

STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code, Project-No)
GUIDE (Guide-No, Guide-name, Guide-research-area, Email-id)
PROJECT (Project-No, Project-title, Project-area, Project-Year-Month, Guide-No, Group-Code)
GROUPS (Group-Code, No-of -Students)

Relational schema exhibiting foreign keys is as under:

STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code, Project-No)

GUIDE (Guide-No, Guide-name, Guide-research-area, Email-id)

PROJECT (Project-No, Project-title, Project-area, Project-Year-Month, Guide-No, Group-Code)

GROUPS (Group-Code, No-of -Students)

ER schema exhibiting entity types and their relationships:

PROJECT
STUDENT GROUPS

GUIDE

2
Add the following constraints on the attributes of the tables:

(1). Add Integer data type for the attribute Roll-No of the table Student.
(2). Add a constraint Check on the attribute Gender of the table Student such that the attribute
will able to accept only ('M','F') values.
(3). Add a constraint on the attribute Degree of the table Student such that no null values could
be inserted in it.
(4). Add appropriate temporal data type for the attribute Project-Year-Month.

Write following SQL queries for the database:

(1). Update details of the guide of the student whose Roll-no is ‘110011’. The details of the
new guide are as Guide-name =‘Ram Mohan’ & Guide-No = ‘11’.
(2). Remove Guide details where Guide-No is ‘15’ and assign a new guide with Guide-No '10'
to all the students who were earlier assigned to the guide with Guide-No '15'.
(3). Get a list of guides who are guiding more than two groups of students.
(4). Get a list of Project-No, Project-title, and names of guides who are guiding projects in the
Project area 'Database'.
(5). Get title of the Project-No ‘5’.
(6). Get names of all the students of the project no. ‘5’.
(7). List all the projects being guided by ‘Dr. S K Jain’.
(8). Get names of all the students being guided by ‘Dr. S K Jain’.
(9). List all the projects completed on ‘June 2019’.
(10). List all the projects completed in year ‘2019’.
(11). Lists roll numbers and names of all the students who have their projects in Project area
“Programming”.
(12). List names of all the teachers who are guiding projects to the students in the Project area
“Network”.
(13). List names of all the students who have their projects in the Project area “Artificial
Intelligence”.
(14). List names of the guides with their Project areas.
(15). Whether Project-No ‘7’ was guided by ‘Dr. S K Jain’ in ‘Dec 2020’.
(16). List names of the students of the groups code ‘G3’.
(17). Retrieve name of the guide of the group ‘G5’.
(18). Retrieve group-codes of the students whose guide is ‘Dr. S K Jain’.

3
Experiment No. 04

Focus: To learn different types of joins.

Create the following tables and insert tuples

Department

Employee DeptName Manager


Sales Ram
Finance Sita
EmpID Name DeptName Accounts Rohit
1101 Ramesh Sales Inventory Gatgi
2241 Suresh Finance
2242 Kamal Sales Office Mohit
2243 Ankur Inventory
2244 Vikas Office
2245 Amir Sales

Students can add more tuples in table Employee.

Using SQL statements, compute the following join operations on the above tables Employee
and Department:

1. Cartesian product
2. Natural join
3. Left outer join
4. Right outer join
5. Full outer join
6. Left semi-join
7. Right semi-join

Remove foreign key constraint and again compute of all join operations; compare results
obtained with the earlier results.

4
Schema for a University Database
Create a relational database for a University described by the following relational schema and
populate it by tuples.

CLASSROOM (Building, Room-Number, capacity)


DEPARTMENT (Dept-name, building, budget)
COURSE (Course-id, title, dept-name, credits)
INSTRUCTER (I-ID, name, dept-name, salary)
STUDENT (S-ID, name, dept-name, tot-credit, I-ID) Here, "I-ID" has been added as foreign key
TIME-SLOT (Time-slot-id, day, start-time, end-time)
SECTION (Course-id, sec-id, semester, year, building, room-number, Time-slot-id, day,
start-time)
TEACHES (I-ID, Course-id, sec-id, semester, year)
TAKES (S-ID, Course-id, sec-id, semester, year, grade)
ADVISES (S- ID, I-ID) Remove relation ADVISES as given in the book.
PREREQ (Course-id, Prereq-id)

The explanations of the relations SECTION, TEACHES, TAKES, ADVISES, and PREREQ are
given below. How these relations represents entity types and relationship types shown in the ER
schema.

Relation “SECTION” represents weak entity type “section” that depends on the strong entity
type “course” in the ER schema. The entity type “course” is an identifying entity type for the
weak entity type "section". The Here, attributes sec-id, semester, and start-time collectively act
as a discriminator for the weak entity type “section”.

Relation “TEACHES” represents many-to-many relationship type “teaches” in the ER schema.

Relation “TAKES” Represents many-to-many relationship type “takes” between weak entity
type “section” and entity type “student” in the ER schema. Here, key attributes of both the
entity types “student” and “section” will constitute the key of the relationship type “takes”. The
key attributes of the relation "TAKES" will be "S-ID, Course-id, sec-id, semester, year"
collectively. The key attribute course-id of the entity type course has been included in the
discriminator "sec-id, semester, year" of the weak entity type section since the entity type
“course” is an identifying entity type for the weak entity type "section". The attribute “grade”
of the relationship type “takes” has values of the grade, e. g., A+, A, B… etc. awarded to the
student in the studied course.

Relation “ADVISES” “represents one-to-many relationship types “adviser” from entity types
“instructor” to “student” in the ER schema. The relation “ADVISES” is unnecessary because
the relationship “adviser” can be implemented by inserting key attribute “I-ID” of the relation
“INSTRUCTOR” as a foreign key in the relation “STUDENT”. The inclusion of the

5
unnecessary relation “ADVISES” will be useful only if a few numbers of students are being
advised instead of all the students. It will save use of unnecessary memory space.
[skj has prepared schema after removing relation ADVISES and inserting I-ID as foreign key in
the relation STUDENT]

Relation “PREREQ” represents many-to-many relationship type “prereq” in the ER schema. It


is basically many-to-many relationship type of the entity type “course” with itself.

Weak entity type


“section” is a weak entity type with discriminator (sec-id, semester, year).

6
In following relational schema, the relation “ADVISES” has been removed. The one-to-many
relationship type “ADVISES” or "adviser" from entity types “Instructor” to “Student” as
shown in the ER schemas (one prepared by S K Jain and other given in the text book) has been
implemented by inserting the foreign key “I-ID” in the relation “STUDENT”.

CLASSROOM (Building, Room-Number, capacity)

DEPARTMENT (Dept-name, building, budget)

COURSE (Course-id, title, dept-name, credits)

INSTRUCTER (I-ID, name, dept-name, salary)

STUDENT (S-ID, name, dept-name, tot-credit, I-ID)

TIME-SLOT (Time-slot-id, day, start-time, end-time)

SECTION (Course-id, sec-id, semester, year, building, room-number, Time-slot-id,

day, start-time)

TEACHES (I-ID, Course-id, sec-id, semester, year)

TAKES (S-ID, Course-id, sec-id, semester, year, grade)

PREREQ (Course-id, Prereq-id)

Time-Slot

Takes
Course
Department Student
Prereq

Advises

Instructor Section Classroom

Teaches

7
The relational schema given in the book is as under

8
Experiment No.-05
Write the following queries in the SQL for the above mentioned database of a university.
(update, retrieve, rename)
(1). Increase Salary by 20 percent of all instructors who are working in Department IT.
(2). Retrieve names of all instructors along with their department names.
(3). Retrieve names of all instructors along with their department names and building names in
which the departments are housed.
(4). Retrieve names of all departments along with names of the buildings in which they are
situated.
(5). Change name of the building "Lecture Hall Complex" to "Lecture Theatre Complex".
(6). Find name of the department of a student with ID _____. (Take a valid ID value of a
student)
(7). Retrieve names of all instructors along with the Course IDs of the courses they teach.
(8). Retrieve Course ID, semester, year and title of each course being taught by "Computer
Engg." department.
(9). Compute monthly salary of all instructors and display it as 'monthly salary' attribute in
place of attribute 'salary'.
(10). Retrieve names of all departments housed in the building named _______. (Consider a
valid Building name)
(11). Find the names of all instructors belonging to Computer Engg. department who have
salary greater than Rs. 70,000.
(12). Find titles of the courses that have credits 3 and offered by the department IT.
(13). Find course names and their credits running in semester 4.
(14). List classes as year and semester wise engaged in room no. LHC-102.
(15). List classes as year, semester and section wise engaged in room no. LHC-102.
(16). List classes as year, semester and section wise engaged in room no. LHC-101.
(17). Retrieve list of room number & time slot where all classes of Computer Engg.. Semester
7th are scheduled.
(18). Retrieve Course titles taught by instructor _______. (Take a valid instructor ID or name)
(19). For all instructors in the university who have taught some course, display their names
along with their department names.
(20). Find the names of all instructors who have a higher salary than some instructor in
"Computer Engg." department.

9
Experiment No.-06
Write the following queries in the SQL for the above mentioned database of a university.
string operation, between, Aggregate, group by

(1). Find names of all departments whose building name includes the substring “Hall”.
(2). Find names of all instructors who have their salaries between Rs. 50,000 and Rs. 80,000.
(3). Find names of all students whose names begin with string "Sa":
(4). Find names of all students belonging to Computer Engg. department and their names begin
with character "Sa":
(5). Retrieve list of courses taught by teachers whose names begin with character "S".
(6). Retrieve list of courses beginning their titles with word "Computer".
(7). Retrieve list of courses containing the word "language" in their titles.
(8). Retrieve names of the instructors who teach courses containing word "language" in their
titles.
(9). Find IDs of all students whose names include "Kumari" and their department is IT.
(10). Find average salary of all instructors.
(11). Find average salary of the instructors belonging to Computer Engg, department.
(12). Find average salary of the instructors belonging to each department.
(13). Find names and average salaries of all departments whose average salary is greater than
Rs. 60000.
(14). Find total number of courses offered by the university.
(15). Find total number of courses offered by the Computer Engg department.
(16). Find total number of courses taught in the Spring 2016 semester.
(17). Find total number of instructors who teach a course in the Spring 2016 semester.
(18). Find maximum salary of an instructor belonging to Computer Engg, department.
(19). Find minimum salary of an instructor belonging to Computer Engg, department.
(20). Find maximum salary of an instructor in the university.
(21). Find total number of students enrolled in the university.
(22). Find total number of students enrolled in each department of the university.
(23). Find instructors whose average salaries are greater than Rs. 42,000.
(24). Find instructors whose average salaries are greater than that of the instructors belonging
to the 'Physics' department.
(25). Retrieve total no. of students in each department who earned total credits more than 8.
10
Experiment No.-07
Write the following queries in the SQL using set operations union, intersect, except, etc. (for the
above mentioned database of a university)
set operations,

1. Find courses taught in Fall 2015 or in Spring 2016. (use union operation)
2. Find courses taught in Fall 2015 and in Spring 2016. (use intersect operation)
3. Find courses taught in Fall 2015 but not in Spring 2016. (use except operation)
4. Find courses taught/offered by Computer Engg. department in Fall 2015 or ECE department
in Spring 2016. (use union operation)
5. Find courses taught/offered by Computer Engg. department in Fall 2015 and ECE
department in Spring 2016. (use intersect operation)
6. Find courses taught/offered by Computer Engg. department in Fall 2015 but not by ECE
department in Spring 2016. (use except operation)

Rewrite queries from 1 to 6 including keyword "all" along with set operations to retain
duplicates in results.

7. List all instructors of the Physics department in alphabetic order.


8. List all coursed offered by Physics department in alphabetic order.

Making use of sub-queries and "in", "not in" connectives, write queries for the following:

9. Find courses taught in Fall 2015 and in Spring 2016. (sub-query, in)
10. Find courses taught in Fall 2015 but not in Spring 2016. (sub-query, not in)
11. Find courses taught/offered by Computer Engg. department in Fall 2015 and ECE
department in Spring 2016. (sub-query, in)
12. Find courses taught/offered by Computer Engg. department in Fall 2015 but not by ECE
department in Spring 2016. (sub-query, not in)
13. Find total no. of distinct students who have taken courses taught in different sections by an
instructor. (Take a valid instructor ID or name)
14. Find names of instructors with salary greater than that of some (at least one) instructors of
the Physics department.
15. Implement the following query and observe the results

select name
from instructor
where salary > some (select salary
from instructor
where Dept name ="Physics")

Based on the observations of the result, write the query in English language. Give your
opinion on any different version of the above query.
16. Find names of all the instructors whose salaries are greater than that of the salaries of all
instructors belonging to the Physics department. (sub-query, "all")

11
17. Using update statement and set keyword

"increase salaries of the instructors whose salaries are greater than 50000" by 15%"
"decrease salaries of the instructors whose salaries are greater than 50000" by 5%"
18. List all departments along with no. of instructors in each department.
19. List all departments along with no. of students in each department.
20. Use a sub-query to derive a relation in "from" clause and write query for the following:
"Find department names along with average salaries of the instructors of that department
where average salaries are greater than Rs. 45000"

"Retrieve name of department along with no. of students who have earned total credits
more than 7"
"Find name of department along with no. of instructors belonging to the department"

21. List instructor name, dept name, and no. of courses taught by the instructor in Sprint 2016.
22. Retrieve departments that have budget amount more than 5 lacs.
23. Find the names of all students who have taken at least one course taught by Computer Engg.
department; make sure there are no duplicate names in the result.

view create, use, drop

12
Database Schema for NIT, Kurukshetra
(Incomplete, under development)

NIT, Kurukshetra is an institute (deemed university) and offers B Tech, M Tech, and PhD
programmes in different disciplines. Students from the whole country and NRI/DASA category
from rest of the world study here. The institute has several departments and in each department
several students study different courses in their programmes. There is a common list of all
courses offered by different departments. Courses may or may not have prerequisite courses,
and a student is expected to clear all the prerequisite courses of a course before opting a course.
A department has several teachers and most of the teachers have specialization in an area. A
teacher also play role of adviser to the students; a teacher can advise maximum five students. A
teacher teaches to one or more section and a section students are taught by several teachers.

PROGRAMME (Program-name)
DISCIPLINE (Discipline-name)
DEPARTMENT (Dept name, dept-code, building-name)
TEACHER (T-ID, name, designation, specialization-area)
STUDENT (Roll-No, name, father-name, native-place, mobile-no)
COURSE (Course-id, title, credits)
SECTION (Section-code, year, semester)
TIME-TABLE-SLOT (Period-No, start-time, end-time)
DAYS (Day-no, day-name)

13
Department
Classroom

Student

Advises

Teacher Section
Time-Slot

Course Takes

Prereq

Classroom

Teaches
Day Period

14
Advanced Experiments (Optional to implement)
1. Write a program in a language (C, C++, Java, etc.) to identify functional dependencies
between pairs of two attributes in the given table.
2. Write a program in a language (C, C++, Java, etc.) to test whether a functional
dependency (take any two attributes in the table) exists or not.

A B C D

a1 b1 c1 d1

a1 b2 c1 d2

a2 b2 c2 d2

a2 b3 c2 d3

a3 b3 c2 d4

3. Using a programming language (C, C++, Java, etc.), implement the algorithm for computing
closure of F, i.e., F+. Test the algorithm by taking F as a set of nay two FDs from the table of
previous experiment.
4.

Implement algorithm for computing closure of attribute sets.

Implement an algorithm for testing whether an attribute is extraneous in a given functional


dependency under a set of FDs holding on a relation schema R.

Implement an algorithm for computing canonical cover.

Include experiments later on Testing lossless decomposition, decomposition of a relation, etc.


(to be done by skj)

15
Experiment No.-09

Create a relational database schema for a Company, described by the following


relations and Insert tuples.

Employee (F-name, L-name, Emp-id, Bdate, Address, Gender, Salary, Super-Emp-


id, D-no)
Department (D-name, D-no, D-Mgr-id, Mgr-start-date )
Dept-Location(D-no, D-location )
Project (P-name, P-number, P-location, D-no )
Works-on (Emp-id, P-no, Hours )
Dependent (Emp-id, Dependent-name, Gender, Bdate, Relationship)

16
Specify the following queries in SQL on the database schema Company

(1). Company decided to give a raiseon salaries of every employee, working on the
‘ProductX’ project by 10 percent.
(2). Find the names and address of all employees who work on same department.
(3). Retrieve the name & employee no of employees, whose salary is between $30,000
and $40,000.
(4). Find the names of all employees who are directly supervised by ‘Franklin
(5). List the name and address of all employees who work for the ‘Research’
department.

17
(6). List the names of employees who works on all project controlled by department
number 5.
(7). List the names of all employees who have a dependent with the same first name as
themselves.
(8). Retrieve the names of all employees in department 5 who work more than 10 hours
per week on XYZ Project.
(9). Retrieve a list of employees and the projects they are working on, ordered by
department and, within each department, ordered alphabetically by last name, then
first name.

18
Experiment No.-09

Specify the following queries in SQL on the database schema Company

(Experiment no. 08)

(1). Retrieve the employee details, whose first name start with “AB”.
(2). Retrieve the employee details, whose third character of first name “S”.
(3). Retrieve all employees, whose address is in Houston, Texas.
(4). Retrieve the employees, whose supervisor city name start name “NEW”.
(5). Retrieve the project name, whose location pin code consists first 3 digits are “111”.
(6). Retrieve the employee name, Employee id, dept no, project no, whose were born
during 1980 and working in a project located at “INDIA”.
(7). Retrieve the total number of Employees in organization.
(8). Count the number of distinct salary values in the Company.
(9). Retrieve the total number of Supervisor in organization.
(10). Retrieve the total no of Female Employee in organization, whose salary is more than
25000.
(11). Retrieve the total number projects currently in company.
(12). Find the sum of the salaries of all employees, the maximum salary, the minimum
salary, and the average salary.
(13). Retrieve the average salary of all female employees.
(14). Retrieve the Employee id & no of projects, employee is working on.
(15). Retrieve employee id, employee name, total no of hours he works on project

19
Experiment No.-10

Specify the following queries in SQL on the database schema Company

(Experiment no. 08)

(1). Retrieve the total no male & female employee in the Organization
(2). Retrieve the total no of employee working, for each of the department
(3). For each department, retrieve the department name and the average salary of all
employees working in that department.
(4). For each project, retrieve the project number, the project name and the number of
employees who work on that project
(5). For each project, list the project name and total no of hours per week (by all
employees) spent on the project.
(6). Retrieve the Project name & no of employee,inwhich least number of employees are
working.
(7). Retrieve the name of department name & department No, number of projects, who
are controlling highest no of projects.
(8). For each project on which more than two employees work, retrieve the project
number, the project name, and the number of employees who work on the project.
(9). For each project, retrieve the project number, the project name, and the number of
employees from department 1 who work on the project.
(10). For each department that has more than five employees, retrieve the department
number and the number of its employees who are making more than $40,000.
(11). Retrieve the names of the employee who do not have supervisors.
(12). Retrieve the names of employees who work on all projects controlled by department
No 05.
(13). Find the names of all employees who earn more than average salary of company.
(14). Make a list of project numbers for projects that involve an employee whose last
name is ‘Smith’, either as a worker or as a manager of the department that controls
the project.

20
Experiment No.-11

Specify the following queries in SQL on the database schema Company

(Experiment no. 08)

(1). Retrieve the names of all employees who work on every project.
(2). List the last name of all department managers who have no dependent.
(3). List the names of managers who have at least one dependent.
(4). Retrieve the names of employees who do not work on any project
(5). Retrieve the names of employees who work on all projects.
(6). Retrieve the name of department name & department No, number of employees,
Number of projects, who is controlling highest no of projects.
(7). List the name of each employee who works on some project controlled by
department number 5.
(8). Retrieve the name of department name & department No, number of employees,
Number of projects, who is controlling highest no of projects.
(9). A view that has the department name, manager name and manager salary for every
department.
(10). A view that has the project name, controlling department, number of employees,
and total hours worked per week for each project.
(11). A view that has the project name, controlling department name, number of
employees, total hours per week on the project for each project with more than one
employee working on it.

21
Assignment – DB Design

A database is being constructed to keep track of the teams and games of asports league. A
team has a number of players, not all of whom participate ineach game. It is desired to
keep track of the players participating in eachgame for each team, the positions they
played in that game, and the result ofthe game. Design an ER schema diagram for this
application, stating anyassumptions you make. Choose your favourite sport (e.g., soccer,
baseball,football).

(1). Find the name of Team, who won the maximum number of matches /games.
(2). Retrieve the name of players of each participating team, who played highest number
of games (for a team).
(3). Retrieve the name of players of each team, who played on every match in which the
team is winning team.
(4). Retrieve the name of venues in which each team won at least a game/match.
(5). Find the name of players for each team in tournament that played at least in three
different positions on different games/matches for each team.
(6). Retrieve the Team Name, Player Name, opponent team, player position for all
matches where team is losing side.

22

You might also like