edited by
25,593 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

Best answer
55 votes
55 votes

Answer is (D)

before $\wedge$ operation all three expressions are the same,

i.e.return true if for each tuple $t$ we have finite no of tuple $u$ in employee table for which they have same employee_name.

(I)  but in $2^{\text{nd}}$ part, for each tuple $v$ in department there may exist infinite no of tuple $t$ for which they may not be equal.

i.e. true for finite no of tuples $\wedge$ true for infinite no of tuples, over all true for finite tuple.

(II) there may exist infinite no of tuple for which at least one tuple $v$ belongs to department table for which they may not be equal.

i.e. true for finite no of tuples $\wedge$ true for infinite no of tuples, over all true for finite tuple.

(III) this one actually true for finite no of tuples, as there may exist only finite tuple which may be equal to at least one tuple $v$ in

department. because department table contain finite no of tuple all tuple $t$ which are same may not be more than all tuple $v$ in

department table in case of equality operation.

      i.e. true for finite $\wedge$ true for finite tuple, over all true for finite tuple.

So all TRC query will return finite tuple which implies all are safe.

References:

edited by
23 votes
23 votes
Answer should be D) as all the bounded variables are tied with one specific Emp and Dept table and does not range over the universe.
edited by
12 votes
12 votes

safe is one that is guaranteed to yield a finite number of tuples as its results. Otherwise, it is called unsafe

as question given

I. {t | ∃ u ∈ EMP (t[EMPName] = u[EmpName] ∧ ∀ v ∈ DEPT (t[DeptId] ≠ DeptId]))} : Gives empnames who donot belong to any department

II. {t | ∃ u ∈ EMP (t[EMPName] = u[EmpName] ∧ ∃ v ∈ DEPT (t[DeptId] ≠ DeptId]))} :  empnames who donot belong to some department

III. {t | ∃ u ∈ EMP (t[EMPName] = u[EmpName] ∧ ∃ v ∈ DEPT (t[DeptId] = DeptId]))}:  empnames who  belong to same department

edited by
11 votes
11 votes
3rd is the employees who are in a department which consists of atleast one employee (that can be they themsleves also)

2nd is the employees for which there exists a department other than their own which means unless in the case of all the employees belonging to the same department are present in the database this will return all the tuples because for every tuple there exists atleast one other tuple which belongs to the other department

1st returns employees whos foriegn key(dept id) is NULL in the EMP table as they may not be assigned to any other department yet

in all the above queries the tuples are coming from the domain which is EMP*DEPT so these are safe queries :)
Answer:

Related questions

52 votes
52 votes
5 answers
1
Arjun asked Feb 14, 2017
12,907 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.