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. (I) { t |∃u ∈ EMP(tEmpName] = u[EmpName] ∧ ∀ v∈ DEPT(t[DeptId] ≠ v[DeptId]))} (II) {t |∃ u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] ≠ v[DeptId]))} (III) {t | ∃ u∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] = v[DeptId]))} Which of the above queries are safe?
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. (I) { t |∃u ∈ EMP(tEmpName] = u[EmpName] ∧ ∀ v∈ DEPT(t[DeptId] ≠ v[DeptId]))} (II) {t |∃ u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] ≠ v[DeptId]))} (III) {t | ∃ u∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] = v[DeptId]))} Which of the above queries are safe? Correct Answer (I), (II) and (III)
Concept:
Safe tuple expression is the one that guaranteed to yield a finite number of tuples as its results. Otherwise, it is called unsafe.
Explanation:
∀ = for all
∃ = There exist / some
Consider the options one by one
Option 1:
{t |∃u ∈ EMP(tEmpName] = u ∧ ∀ v∈ DEPT(t ≠ v))}
It gives all the name of employees who do not belong to the any department. Before ∧ operator, it results in finite tuples, after ∧ it results in infinite number of tuples. Finite ∧ infinite results in finite number of tuples. So, it is safe expression
Option 2:
{t |∃ u ∈ EMP(t = u ∧ ∃ v ∈ DEPT(t ≠ v))}
It gives the employee names who do not belong to some department. Before ∧ it is finite, after ∧ it is infinite. Results in a finite number of tuples. So, it is safe expression.
Option 3:
{t | ∃ u∈ EMP(t = u ∧ ∃ v ∈ DEPT(t = v))}
This expression gives the name of employees who belongs to atleast one same department. It also results in a finite expression. So, it is safe expression.
All three are safe expressions.