search
Log In
0 votes
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.?
in Databases 201 views

Please log in or register to answer this question.

Related questions

0 votes
0 answers
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?
asked Nov 28, 2018 in Databases Ayush Upadhyaya 93 views
1 vote
1 answer
2
148 views
$(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$
asked Jul 10, 2018 in Databases Prateek Raghuvanshi 148 views
1 vote
0 answers
3
105 views
How does the evaluation will be done?
asked Jan 11, 2018 in Databases AnilGoudar 105 views
0 votes
0 answers
4
134 views
How to solve SQL problems related to subqueries quickly? Though I have concepts still I face some difficulties in solving this problems
asked Dec 23, 2017 in Databases soumayan bandhu 134 views
...