# Unsafe TRC Query

201 views
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.

Query 1

{t | ∃u ∈ EMP(t[EmpName] ≠ u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] ≠ v[DeptId]))}

I think above query is unsafe because there will be infinite number of tuples such that whose EmpName don't appear in EMP table and also that their deptId does not appear in any record of the department table.So, the tuples that appear in the result are out of the domain of the expression given, hence Unsafe expression.

However

Query 2

{t | ∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] ≠ v[DeptId]))}

This query is safe because,it will only select those tuples such that the EmpName attribute value appears in EMP Relation and for this Employee, his department Id must not match with the all the department Id present in the relation DEPT.Hence, it should select all EmpName, whose Department Id is Null.

So, here it is guaranteed that the tuples which will occur in the result set will be in the domain of the expression given.

Am I correct in reasoning for both of the queries.?

## Related questions

1
93 views
Consider two relation schemas $R(A,B,C)$ and $S(D,E,F)$ Give an expression in the tuple relational calculus that is equivalent to each of the following. (a)$\pi_A(r)$ ->$\{t|t \in r\land t[A]=r[A]\}$ (b)$\sigma_{B=17}(r)$-$\{t|t \in r \land t[B]=17\}$ ... Are my queries Correct?
1 vote
$(e.Fname$|$EMPLOYEE(e)\ AND\ ((\forall_{d})[ (DEPENDENT(d)\ AND\ d.ssn= e.ssn \ AND\ (d.sex='M'))\rightarrow (d.age>30))] )$ EMPLOYEE Fname SSn Sex Ram 1 M Shyam 2 M Ravi 3 M Sita 4 F DEPENDENT SSN SEX AGE 1 M 35 1 F 25 1 M 15 2 ... on the basis of above instances of tables, which of the following option is true of output of above query?? $Ram,Shyam,Ravi,Sita$ $Shyam ,Ravi,Sita$ $Shyam$ $Empty$