Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practical Assessment

IS-201 (Fundamental Database Management System)


Faculty of Information Science

Q1. Given the Pet database tables,


Pet_Owner (Owner_ID, O_firstname,O_lastname, Address)
Pet (Pet_ID, Petname, Ptype, Pbreed, PDOB, PWeight, Owner_ID)

Data values for Pet_Owner


(1, James,Ham, Yangon),
(2, Liz,Chole, ShwePyiThar),
(3, Mon,Han, Thuwanna),
(4, Monn,Lapyae, Tamwe)

Data values for Pet


(P-1, Teddy,Dog,Sport, 27-2-2012, 10.5, 2),
(P-2, Fudo, Cat, Mix, 1.1.2011, 12, 1),
(P-3, Cris,Rabbit, Unknown, 28.7.2013, 2.5 ,1),
(P-4, Twist,Hamster, Parpi, 12.6.2023, 1, 3)
(P-5, Gold,Dog,Rich, 8.4.2021, 25.5 ,4)

(a) Write an SQL statement to display the breed, type and DOB for all pets having the type
Dog and the breed Rich.
(b) Write an SQL statement to display the pet ID, breed and type for all pets having a five
character name starting with T.
(c) Write an SQL statement to display the average weight per pet breed. Consider breeds for
which two or more pets are included in the database, but do not consider any pet having
the breed of Unknown.
(d) Find the Owner’s address of pet id 3.
(e) Find the youngest of pet in dog.
Q2. Write the following queries in SQL, using the university schema.
classroom(building, room_number, capacity)
department(dept_name, building, budget)
course(course_id, title, dept_name, credits)
instructor(ID, name, dept_name, salary)
section(course_id, sec_id, semester, year, building, room number, time slot id)
teaches(ID, course_id, sec_id, semester, year)
student(ID, name, dept_name, tot cred)
takes(ID, course_id, sec_id, semester, year, grade)
advisor(s_ID, i_ID)
time slot(time_slot_id, day, start_time, end_time)
prereq(course_id, prereq_id)

(a) Find the ID and name of each student who has not taken any course offered before 2017.
(b) Find the ID and name of each student who has taken at least one Comp.Sci. course, make
sure there are no duplicate names in the result.
(c) For each department, find the maximum salary of instructors in that department. You may
assume that every department has at least one instructor.
(d) Increase the salary of each instructor in the Comp. Sci. department by 15%.
(e) Enroll every student in the Comp. Sci. department.

Answers

1. (a) SELECT Pbreed, Ptype, PDOB FROM pet WHERE Ptype = "Dog" AND Pbreed =
"Rich";

(b) SELECT Pet_ID, Pbreed, Ptype FROM pet WHERE Petname LIKE "%T____";

(c) SELECT Pbreed , AVG(Pweight) FROM pet GROUP BY Pbreed HAVING Pbreed <>
‘Unknown’ AND Count(*) >= 2;

(d) SELECT Address FROM Pet_Owner LEFT JOIN pet ON pet.Owner_ID =


Pet_Owner.Owner_ID WHERE Pet_ID = "P-3";

(e) SELECT MAX(STR_TO_DATE(PDOB, '%d-%m-%Y')) AS youngest_dog FROM pet


WHERE Ptype = 'Dog';
2. (a) SELECT student.ID, student.name FROM student LEFT JOIN takes ON takes.ID =
student.ID AND year < 2017 WHERE takes.ID is NULL;

(b) SELECT DISTINCT student.ID, student.name FROM student INNER JOIN takes ON
takes.ID = student.ID INNER JOIN course ON course.course_id = takes.course_id
WHERE course.dept_name = ‘Comp. Sci.’;

(c) SELECT dept_name, MAX(salary) FROM instructor GROUP BY dept_name;

(d) UPDATE instructor SET salary = salary * 1.15 WHERE dept_name = ‘Comp. Sci.’;

(f) INSERT INTO takes (id, course_id, sec_id, semester, year)


SELECT student.id, ‘CS-001’, ‘1’, ‘Fall’, 2017 FROM student WHRE
student.dept_name = ‘Comp. Sci.’;

You might also like