0% found this document useful (0 votes)
33 views5 pages

Cycle 1

The document outlines a series of problems related to database management systems (DBMS) involving the creation, alteration, and manipulation of database tables. It includes tasks such as creating tables with constraints, writing SQL queries for data retrieval, and using aggregate functions. Additionally, it covers nested queries for advanced data retrieval scenarios in a university database context.
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)
33 views5 pages

Cycle 1

The document outlines a series of problems related to database management systems (DBMS) involving the creation, alteration, and manipulation of database tables. It includes tasks such as creating tables with constraints, writing SQL queries for data retrieval, and using aggregate functions. Additionally, it covers nested queries for advanced data retrieval scenarios in a university database context.
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/ 5

CS 262 – DBMS Lab

Cycle - 1

Problem 1
Consider the following database schema:

1. Create the tables in the database.


2. Alter the employee table by adding a new attribute contact_number.
3. Alter the Department table by modifying the datatype of Location attribute.
4. Alter the Department table by dropping Location attribute.
5. Show the structure of the Employee table.
6. Load the database with data using insert statements.
7. Retrieve the contents of a table using select statements.
8. Modify the contents of tables using update statements.
9. Delete selected records from the tables.
10. Truncate Department table.
11. Drop a Department table.
12. Commit the changes made to the database.
Problem 2
Consider the following database schema:

1. Create Employee and Department tables by adding following constraints on the

attributes:

a. Primary keys on Eno and Dno attributes.

b. Foreign key constraints on Supervisor_No and Dept_No attributes of

Employee table.

c. Unique on the combination of Fname and Lname attributes.

d. Not null on Fname attribute.

e. Check constraint on salary attribute of Employee table. Salary should be

between 20,000 to 1,50,000.

f. Set default value for department attribute of Employee table.

2. Write insert statements that violate the constraints specified in question 1.

3. Write update statements that violate the constraints specified in question 1.

4. Write delete statements that violate the constraints specified in question 1.

5. Drop the constraints specified in question 1 using alter table statements.

6. Add the constraints specified in question 1 using alter table statements.


Problem 3

Answer the following by specifying queries on the university database:


I. Write SQL Select Statements for the following simple queries that retrieve data from
a single table:
1. Find the details of all students.
2. Find the department names of instructors.
3. Find the names of all the instructors from Biology department
4. Find the names of all instructors in the Computer Science department who have
salaries greater than $70,000.
5. Find the names of courses in Computer science department which have 3 credits
6. Find the names of the instructors, their present salaries and the resulting salaries
if they were given a 10% raise.
7. Find the names of instructors with salary amounts between $90,000 and
$100,000,
8. Find all instructors whose salary is unknown.
9. Find the names of all departments whose building name includes the substring
‘Watson’.
10. Find departments whose names contain the string “sci” as a substring, regardless
of the case.
11. List the names of all instructors in the Physics department in alphabetic order.
12. List the entire instructor relation in descending order of salary. If several
instructors have the same salary, order them in ascending order by name.

II. Write SQL queries for retrieving data from multiple tables using Joins:
1. Find all possible combinations of instructors and the courses they teach.
2. Retrieve the names of all instructors, along with their department names and
department building name.
3. Find the names of instructors who have taught at least one course.
4. For the student with ID 12345 (or any other value), show all course_id and title of
all courses registered for by the student.
5. Find instructor names and course identifiers for instructors in the Computer
Science department.
6. For all instructors in the university who have taught some course, find their
names and the course ID of all courses they taught.
7. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department. Or Find the names of all instructors who earn
more than the lowest paid instructor in the Biology department.
8. Find full details of instructors who teach at least one course.
9. Find the instructor names and the courses they taught for all instructors in the
Biology department who have taught some course.
10. Find the set of all courses taught either in Fall 2009 or in Spring 2010, or both.
11. Find all courses taught in the Fall 2009 semester but not in the Spring 2010
semester.
12. Find the names of all students who have taken any Comp. Sci. course ever. (there
should be no duplicate names)
13. Display the IDs of all instructors who have never taught a course. (Don’t write
nested query)
Problem 4

I Write SQL Select Statements using Aggregate Functions, Group By and Having
clauses for the following queries that retrieve data from university database:
1. Find the maximum and average capacity of buildings in the university.
2. Display the least budget of the departments.
3. Find the total number of courses and credits offered by Biology
department.
4. Find the average salary of instructors in the Computer Science
department.
5. Find the total number of instructors who teach a course in the Spring
2010 semester.
6. Find the average salary in each department.
7. Find the number of instructors in each department who teach a course in
the Spring 2010 semester.
8. Find the department name and average salary of the department for only
those departments where the average salary of the instructors is more
than $42,000.
9. For each course section offered in 2009, find the average total credits
(tot_cred) of all students enrolled in the section, if the section had at least
2 students.
10. For each department, find the maximum salary of instructors in that
department. You may assume that every department has at least one
instructor.
11. For the student with ID 12345 (or any other value), show the total
number of credits scored for all courses (taken by that student). Don't
display the tot_creds value from the student table, you should use SQL
aggregation on courses taken by the student.
12. Display the total credits for each of the students, along with the ID of the
student; don't bother about the name of the student. (Don't display the
tot_creds value from the student table, you should use SQL aggregation on
courses taken by the student. For students who have not registered for
any course, tot_creds should be 0)
II Write nested queries for answering the following queries that retrieve data from
university database:
1. Find the total number of (distinct) students who have taken course
sections taught by the instructor with ID 110011
2. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department
3. Find the departments that have the highest average salary.
4. Find all the courses taught in the both the Fall 2009 and Spring 2010
semesters
5. Find all the courses taught in the Fall 2009 semester but not in the Spring
2010 semester.
6. Find all courses taught in both the Fall 2009 semester and in the Spring
2010 semester. (Write correlated nested Query)
7. Find all students who have taken all courses offered in the Biology
department. (Write Correlated nested Query)
8. Find all courses that were offered at most once in 2009.
9. Find all courses that were offered at least twice in 2009”
10. Find the average instructors’ salaries of those departments where the
average salary is greater than $42,000.
11. Find the departments with the maximum budget.
12. Find the names of instructors who have not taught any course.
13. Find the IDs and names of all students who have not taken any course
offering before Spring 2009.
14. Find the lowest, across all departments, of the per-department maximum
salary computed.
15. Display the IDs and names of the instructors who have taught all Comp.
Sci. courses.

You might also like