in Databases
1,560 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.?
in Databases
1.6k views

Please log in or register to answer this question.

Related questions

1 vote
1 vote
0 answers
3