edited by
25,609 views
54 votes
54 votes

Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus.

  1. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\forall$v $\in$ DEPT(t[DeptId] $\neq$ v[DeptId]))}
  2. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\exists$v $\in$ DEPT(t[DeptId] $\neq$ v[DeptId]))}
  3. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\exists$v $\in$ DEPT(t[DeptId] $=$ v[DeptId]))}

Which of the above queries are safe?

  1. I and II only
  2. I and III only
  3. II and III only
  4. I, II and III
edited by

5 Answers

1 votes
1 votes

All the above explanations are simply amazing but I want to add one point . One of the simplest way to check whether query is safe or not , one should check whether “free variable” (variable not bounded by quantifiers) is complemented in query or not , if not then it is definitely safe . Hence ans here seems to be D)

Answer:

Related questions

52 votes
52 votes
5 answers
1
Arjun asked Feb 14, 2017
12,919 views
Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.$$\begin{array}{|c|c|} \hline \textbf{Student...
3 votes
3 votes
0 answers
4
Warlock lord asked Jan 19, 2018
1,068 views
Is the query below safe? {t | ∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] == v[DeptId]))}Please explain why.