• edited by
38,370 views
71 71 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

8 Answers

Best answer
68 68 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
29 29 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
26 26 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
11 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 :)
2 2 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)

2 2 votes
To solve this question you need 2 things to understand
1.what is safe query?
->query which is not returning infinite number of tupples
eg of unsafe query so that you can understand it better
->{t | t doesn't belong to EMP}
   here return tuples which doesn't belong to EMP which can be infinite
2.how to read calculas query?
->{t | .......} means t such that where t is tuple

now i think anyone can solve this question

but still for easness given 3 queries are like first half telling that tuple of EMP table and 2nd half like DepId and there variation
Answer:
Position:
Show:

Related questions

73 73 votes
5 answers 5 answers
22.0k
22.0k views
Arjun asked Feb 14, 2017
21,950 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...
125 125 votes
5 answers 5 answers
43.7k
43.7k views
Arjun asked Feb 14, 2017
43,745 views
In a database system, unique timestamps are assigned to each transaction using Lamport's logical clock. Let $TS(T_{1})$ and $TS(T_{2})$ be the timestamps of transactions ...
97 97 votes
3 answers 3 answers
24.4k
24.4k views
Arjun asked Feb 14, 2017
24,424 views
The following functional dependencies hold true for the relational schema $R\left \{V,W,X,Y,Z \right \}$:$V \rightarrow W$$VW \rightarrow X$$Y \rightarrow VX$$Y \rightarr...
3 3 votes
0 0 answers
1.8k
1.8k views
Warlock lord asked Jan 19, 2018
1,844 views
Is the query below safe? {t | ∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] == v[DeptId]))}Please explain why.