0% found this document useful (0 votes)
26 views

Assignment 2b

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Assignment 2b

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Find the id and title of all courses which do not require any prerequisites.

Sol: select course_id, title 


from course 
where course_id not in (select course_id from prereq);

2. Find the names of students who have not taken any biology dept courses
Sol: select name 
from student 
where not exists (select * from takes, course 
where takes.course_id=course.course_id 
and course.dept_name = 'Biology' 
and takes.ID = student.ID)

3. Write SQL update queries to perform the following:


1. Give a 10% hike to all instructors
Sol: update instructor set salary = (1.1 * salary)

2. The academic office made a mistake in entering the credits for the course BIO-301, which
should have been 6 credits not 4. Fix this by updating the course relation, and also
increasing the tot_creds by 2 for all students who have taken the course titled "Genetics"
and got a grade that is neither F nor null.
Sol: update course set credits = 6
where course_id = 'BIO-301';

update student set tot_cred = tot_cred + 2
where student.ID in (select takes.ID from takes 
where takes.course_id=course.course_id 
and course.course_id = 'BIO-301'
and grade <> 'F' and grade is not null)

3. For all instructors who are advisors of at least 2 students, increase their salary by 1000.
Sol: update instructor set salary = salary + 1000 where instructor.ID in
(select i_id from advisor 
group by i_id 
having count(s_id) > =2 )

(or)

update instructor set salary = salary + 1000 


where 2 <= (select count(*) from advisor where i_id = instructor.ID)

4. Insert a new instructor named Kalam, with any ID, dept_name and salary of your choice. Also add
Kalam as an advisor of student 00128.
Sol: insert into instructor(id, name, dept_name, salary) 
values (11111, 'Kalam', 'Biology', 20000);
insert into advisor(s_id, i_id) values ('00128', '11111');

5. Delete all advisor relationships for all instructors named Kalam (this should work even if Kalam
was advising students other than 00128 above!).
Sol: delete from advisor 
where i_id = (select id from instructor where name = 'Kalam');

You might also like