



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




iii.
(s)
vi. As this query contains a subquery in where clause we had to transform it into an equivalent SQL query
s ← student + takes t ← s + course πname (σcourse.dept name=”Comp.Sci.” (t))
vii. t ← ρteacherIDs (πID (instructor + teaches))) s ← πID (instructor)
s−t viii. s ← takes + student σyear=′ 2010′ (s)
ix. s ← σyear≥′ 2008′ (takes) + student
t ← ρtakes2008 (s) πname,coursei d (t)
x. s ← πperson name (σage>21 ) t ← ρstudy21 (s)
u ← ρS (πperson name (student)) u − (u − t)
i. select name from instructor where dept name=’Biology’ {t| ∃ s ∈ instructor(t[name] = s[name] ∧ s[dept name] =′ Biology ′ )}
ii. select title from course
where dept name=”Comp. Sci” and credits= {t| ∃ s ∈ course(t[title] = s[title] ∧ s[dept name] =′ Comp.Sci.′ ∧ s[credits] = 3)}
iii. select course id, title
takes as T natural join course where ID=’12345’; {t| ∃ s ∈ takes, ∃ c ∈ course(t[course id] = s[course id] ∧ t[title] = c[title] ∧ s[course id] = c[course id] ∧ s[ID] = 12345)}
iv. ignored
v. ignored
vi. Q ← select distinct name from student
where exists (select * from student natural join takes where dept name = ”Comp. Sci.”) as takeCS; Q’←select distinct name from student natural join takes join course where course.dept name=”Comp. Sci.”; {t| ∃ s ∈ student, ∃ u ∈ takes, ∃ c ∈ course(t[name] = s[name] ∧ s[ID] = u[ID] ∧ u[course id] = c[course id] ∧ c[dept name] = ”Comp.Sci.”)}
vii. Q← select ID from instructor where ID not in(select ID from instructor natural join teaches) as teacherIDs; From equation of set difference in tuple calculus {t|t ∈ r ∧ ¬ (t ∈ s)} equal to r − s I write equation below {t| ∃ s ∈ instructor(t[ID] = s[ID]) ∧ ¬( ∃ u ∈ teaches(t[ID] = u[ID]))};
viii. Select * from takes natural join student where ’year’≤2010’;
{t| ∃ u ∈ takes, ∃ s ∈ student(t[ID] = u[ID] ∧ t[course id] = u[course id] ∧ t[sec id] = u[sec id] ∧ t[semester] = u[semester] ∧ t[year] = u[year] ∧ t[grade] = u[grade]
∧ t[name] = s[name] ∧ t[dept name] = s[dept name] ∧ t[tot cred] = s[tot cred] ∧ u[ID] = s[ID] ∧ u[year] ≤ 2010}
ix. select name, course id from ((select * from takes where ’year’ ≥ 2008) natural join student) as
takes 2008 {t| ∃ u ∈ takes(u[year] ≥ 2008) ∧ ∃ s ∈ student(u[ID] = s[ID] ∧ t[course id] = u[course id] ∧ t[name] = s[name])}
x. Q ← select person name from student as S
where S.person name in (select studies.person name ] from studies where age>21) as study Q’ ← select person name from student as S natural join studies where age> {t| ∃ S ∈ student, ∃ study21 ∈ studies(t[person name] = S[person name] ∧ S[person name] = study21[person name] ∧ study21[age] > 21)}
xi. select I.name, T.course id
from instructor as I join teaches as T using (ID); {t| ∃I ∈ instructor, ∃ T ∈ teaches(t[name] = I[name] ∧ t[course id] = T [course id] ∧ I [ID] = T [ID])}
xii. { t| ∃ i ∈ instructor, ∃ q ∈ teaches(i[ID] = q[ID]) ∧ ∃ s ∈ student, ∃ p ∈ takes(s[ID] = q[ID]) ∧ q[course id] = p[course id] ∧ q[sec id] = p[sec id] ∧ q[semester] = p[semester] ∧ q[year] = p[year] ∧ i[name] = ”Einstein” 𝖠𝖠 t[ID] = s[ID]) };
∧ ii = id ∧ ∃ is, d, t < is, n, d, t >∈ student 𝖠𝖠 < idt, cit, sit, st, yt, gt > ∈ takes ∧ is = idt ∧ ∧ id = idt ∧ ci = cit ∧ si = sit ∧ s = st ∧ y = yt ∧ ni = ”Einstein”)}