Assignment 2b
Assignment 2b
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)
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)
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');