1,620 views
0 votes
0 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.

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.?

Please log in or register to answer this question.

Related questions

1 votes
1 votes
0 answers
1
Ayush Upadhyaya asked Nov 28, 2018
435 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...
1 votes
1 votes
0 answers
3
AnilGoudar asked Jan 11, 2018
498 views
How does the evaluation will be done?
0 votes
0 votes
0 answers
4
soumayan bandhu asked Dec 22, 2017
294 views
How to solve SQL problems related to subqueries quickly?Though I have concepts still I face some difficulties in solving this problems