DBMS Lab File
DBMS Lab File
Create tables and insert tuples in the databases described by the following
relational schemas.
Create a database for the following relational schema and insert tuples.
(1). Change data type of the attribute Roll-No of the table Student from
Number (10) to Varchar (10)
. (2). Add a constraint Check on 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.
(5). Get a list of Project-No, Project-title, and names of guides who are
guiding projects in the Project area 'Database'.
(6). 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’.
(7). 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'.
Experiment No. 04
Department
DeptName Manager
Sales Ram
Finance Sita
Accounts Rohit
Inventory Gatgi
Office Mohit
Using SQL statements, perform following joins on the above tables Employee
and Department:
1. Cartesian product
2. Natural join
3. Left outer join
4. Right outer join
(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'.
(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-104.
(17). Retrieve list of room number & time slot where all classes of
Computer Engg.. Semester 7th are scheduled.
(20). Find the names of all instructors who have a higher salary than
some instructor in "Computer Engg." department.
Experiment No.-06
Write the following queries in the SQL for the above-mentioned database
of a university.
(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.
40,0000 and Rs. 50,0000.
(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
(5). Retrieve list of courses taught by teachers whose names begin with
character "S".
(6). Retrieve list of courses beginning their titles with word "o".
(7). Retrieve list of courses containing the word "fa" 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 "an" and their department
is IT.
(10). Find average salary of all instructors.
(13). Find names and average salaries of all departments whose average
salary is greater than
Rs. 400000.
(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 3rd semester 2018.
(17). Find total number of instructors who teach a course in the 3rd
semester 2018.
(18). Find maximum salary of an instructor belonging to Computer Engg,
department.
(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
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)
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)
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.
select name from instructor where salary > some (select salary from
instructor where Dept name ="Physics")
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:
"Retrieve name of department along with no. of students who have earned
total credits more than 7"
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.
Experiment No.-08
Dept-Location(D-no, D-location )
(3).Retrieve the name and employeeno of all the employees who have salary
between $30,000 and $40,000.
(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.
Experiment No.-09
(1). Retrieve the employee details, whose first name start with “AB”.
(2). Retrieve the employee details, whose third character of first name
“S”.
(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”.
(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.
(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.
(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
Experiment No.-11
Specify the following queries in SQL on the database schema Company
(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
(6). Retrieve the name of department name & department No, number of
employees,
department number 5.
(8). Retrieve the name of department name & department No, number of
employees,
department.
(10). A view that has the project name, controlling department, number of
employees,
employees, total hours per week on the project for each project with more
than one