The Gateway to Computer Science Excellence
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.


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 by Boss (29k points) | 100 views

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,258 answers
104,737 users