Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

∏ (Σ (P×R) ) −∏ (Σ (Q×R) ) 2. Q: R⋈ (Σ (S) ) : Σ (R⋈S) B) Σ (Rlojs) Rloj (Σ (S) ) D) Σ (R) Lojs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1. Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V).

P
X Y Z
X1 Y1 Z1
X1 Y1 Z2
X2 Y2 Z2
X2 Y4 Z4
Q
X Y T
X2 Y1 2
X1 Y2 5
X1 Y1 6
X3 Y3 1
R
Y V
Y1 V1
Y3 V2
Y2 V3
Y2 V2
How many tuples will be returned by the following relational algebra query?
∏X(σ(P.Y=R.Y∧R.V=V2)(P×R))−∏X(σ(Q.Y=R.Y∧Q.T>2)(Q×R))

2. Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key
referencing s.B. Consider the query Q : r⋈(σB<5(S))
Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.
Which one of the following queries is NOT equivalent to Q?

A) σB<5(r⋈S) B) (B) σB<5(rLOJs)σB<5(rLOJs)

C) (C) rLOJ(σB<5(s)) D) (D) σB<5(r)LOJs

3. Consider a database that has the relation schems EMP(Empld, EmpName, DeptId),
and DEPT(DeptName, DeptId). Note that the DeptId can be permited to be NULL in the
relation EMP. Consider the following queries on the database expressed in tuple relational
calculus.
(I){t|∃u∈EMP(t[EmpName]=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?
A) (I) and (II) only C) (II) and (III) only
B) (I) and (III) only D) (I) ,(II) and (II)

4. Consider a database that has the relation schema CR(StudentName, CourseName). An


instance of the schema CR is as given below.

CR
StudentName CourseName
SA CA
SA CB
SA CC
SB CB
SB CC
SC CA
SC CB
SC CC
SD CA
SD CB
SD CC
SD CD
SE CD
SE CA
SE CB
SF CA
SF CB
SF CC
The following query is made on the database.
T1←πCourseName(σStudentName=′SA′(CR)); T2←CR÷T1
The number of rows in T2 is__________
5. Which of the following is NOT a superkey in a relational schema with
attributes V,W,X,Y,Z and primary key V Y?
A) V X Y Z B) VWXZ C) VWXY D) VWXYZ
6. Consider two relations R1(A,B) with the tuples(1, 5), (3, 7) and R2(A, C) = (1, 7), (4, 9). Assume
that R(A,B,C) is the full natural outer join of R1 and R2. Consider the following tuples of the form
(A, B, C): a =(1, 5, null), b =(1, null, 7), c = (3, null, 9), d = (4, 7, null), e = (1, 5, 7), f = (3,
7, null), g = (4, null, 9). Which one of the following statements is correct?
A) R contains a, b, e, f, g but not c, d. C) R contains e, f, g but not a, b
B) R contains all of a, b, c, d, e, f, g. D) R contains e but not f,g.
7. Consider a join (relation algebra) between relations r(R) and s(S) using the nested loop
method. There are 3 buffers each of size equal to disk block size, out of which one buffer is
reserved for intermediate results. Assuming size (r(R))<size(s(S)), the join will have
fewer number of disk block accesses if
A) relation r(R) is in the outer loop. C)join selection factor between r(R) and s(S) is
more than 0.5
B) relation s(S) is in the outer loop D) join selection factor between r(R) and s(S) is
less than 0.5
8. What is the optimized version of the relation algebra expression πA1(πA2(σF1(σF2(r)))),
where A1, A2 are sets of attributes in r with A1 ⊂ A2 and F1, F2 are Boolean expressions
based on the attributes in r?
A) πA1(σ(F1ΛF2)(r)) B) πA1(σ(F1∨F2)(r)) C) πA2(σ(F1∧F2)(r)) D) πA2(σ(F1∨F2)(r))

9. Consider the relational schema given below, where eId of the relation dependent is a
foreign key referring to empId of the relation employee. Assume that every employee has at
least one associated dependent in the dependent relation.
employee (empId, empName, empAge); dependent(depId, eId, depName,
depAge)
Consider the following relational algebra query:
πempId(employee)−πempId(employee⋈(empId=eID)∧(empAge≤depAge)Dependent)
The above query evaluates to the set of empIds of employees whose age is greater than that
of
A) Some dependent B) All dependents C) Some of his/her dependents D) All of
his/her dependents
10. Consider the following relational schema: Students(rollno: integer, sname: string);
Courses(courseno: integer, cname: string); Registration(rollno: integer, courseno: integer,
percent: real).
Which of the following queries are equivalent to this query in English? “Find the distinct names
of all students who score more than 90% in the course numbered 107”
(I) SELECT DISTINCT S.sname FROM Students as S, Registration as R WHERE
R.rollno=S.rollno AND R.courseno=107 AND R.percent >90;
(II) ∏sname(σcourseno=107∧percent>90(Registration⋈Students)
(III) {T | ∃S∈∈ Students, ∃ R∈∈ Registration ( S.rollno=R.rollno ∧ R.courseno=107 ∧
R.percent>90 ∧T.sname=S.sname)}
(IV) {<SN> | ∃SR ∃RP ( <SR, SN>∈∈ Students ∧ <SR, 107, RP>∈∈ Registration ∧ RP>90)}
A) I, II, III and IV B) I, II, III only C) I, II, IV only D) II, III, IV only
11. Suppose R1(A, B) and R2(C, D) are two relation schemas. Let r1 and r2 be the corresponding
relation instances. B is a foreign key that refers to C in R2. If data in r1 and r2 satisfy referential
integrity constraints, which of the following is ALWAYS TRUE?
A) ΠB(r1)−ΠC(r2)=∅ B) ΠC(r2)−ΠB(r1)=∅ C) ΠB(r1)=ΠC(r2)
D) ΠB(r1)−ΠC(r2)≠∅
12. Consider a relational table with a single record for each registered student with the following
attributes.
1. Registration_Num: Unique registration number of each registered student
2. UID: Unique identity number, unique at the national level for each citizen
3. BdnkAccount_Num: Unique account number at the bank. A student can have
multiple accounts or joint accounts. This attribute stores the primary account number.
4. Name: Name of the student
5. Hostel_Room: Room number of the hostel
Which of the following options is INCORRECT?
A) BankAccount_Num is a candidate key C) UID is a candidate key if all students are
from the same country
B) Registration_Num can be a primary key D) If S is a superkey such
that S∩UIDS∩UID is NULL then S∪UIDS∪UID is also a superkey
13. Consider a relational table r with sufficient number of records, having
attributes A1, A2,……An and let 1 ≤ p ≤ n. Two queries Q1 and Q2 are given below.
Q1: π A1......Ap(σAp=c(r)) where c is a constant
Q2: π A1......Ap(σ c1≤Ap≤c2(r)) where c1 and c2 are constants
The database can be configured to do ordered indexing on Ap or hashing on Ap. Which of the
following statements is TRUE?
A) Ordered indexing will always outperform hashing for both queries
B) Hashing will always outperform ordered indexing for both queries
C) Hashing will outperform ordered indexing on Q1, but not on Q2
D) Hashing will outperform ordered indexing on Q2, but not on Q1
14. Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following
queries on the database:
I.πR−S(r)−πR−S(πR−S(r)×S−πR−S,S(r))
II. {t|t∈πR−S(r)∧∀u∈s(∃v∈r(u=v[s]∧t=v[R−S]))}
III. {t|t∈πR−S(r)∧∀v∈r(∃u∈s(u=v[s]∧t=v[R−S]))}
IV. Select R.a, R.b from R, S where R.c = S.c;
Which of the above queries are equivalent?
A) I & II only B) I & III only C) II & IV only D) III & IV only
15. Consider the following relational schema: Suppliers ( sid:integer, sname:string, city:string,
street:string); Parts(pid:integer, pname:string, color:string); Catalog(sid:integer, pid:integer,
cost:real). Consider the following relational query on the above database:
SELECT S.sname
FROM Suppliers S
WHERE S.sid NOT IN (SELECT C.sid
FROM Catalog C
WHERE C.pid NOT (SELECT P.pid
FROM Parts P
WHERE P.color<> 'blue'))
Assume that relations corresponding to the above schema are not empty. Which one of the
following is the correct interpretation of the above query?
A) Find the names of all suppliers who have supplied a non-blue part.
B) Find the names of all suppliers who have not supplied a non-blue part
C) Find the names of all suppliers who have supplied only blue parts
D) Find the names of all suppliers who have not supplied only blue parts
16. Consider the following relational schema: Suppliers(sid:integer, sname:string, city:string,
street:string); Parts(pid:integer, pname:string, color:string); Catalog(sid:integer, pid:integer,
cost:real)
Assume that, in the suppliers relation above, each supplier and each street within a city has a
unique name, and (sname, city) forms a candidate key. No other functional dependencies are
implied other than those implied by primary and candidate keys. Which one of the following is
TRUE about the above schema?
A) The schema is in BCNF B) The schema is in 3NF but not in BCNF
C) The schema is in only 2NF D) The schema is not in 2NF
17. Which of the following tuple relational calculus expression(s) is/are equivalent to ∀t∈r(P(t))?
I. ¬∃t∈r(P(t))
II.∃t∉r(P(t))
III. ¬∃t∈r(¬P(t))
IV. ∃t∉r(¬P(t))
A) I only B) II only C) III only D) III & IV only
18. Let R and S be two relations with the following schema: R (P,Q.R1,R2,R3); S (P,Q,S1,S2)
Where {P, Q} is the key for both schemas. Which of the following queries are equivalent?
∏p (R ⋈ S)
II. ∏p (R) ⋈⋈ ∏p (S)
III. ∏p (∏p, Q (R) ∩ ∏ p, Q (S))
IV. ∏p (∏p, Q (R) - (∏p, Q (R) - ∏ p, Q (S))
A) Only I and II B) Only I and III C) Only I, II, III D) Only I, III and IV
19. Information about a collection of students is given by the relation studInfo(studId, name,
sex). The relation enroll(studId, courseId) gives which student has enrolled for (or taken)
what course(s). Assume that every course is taken by at least one male and at least one
female student. What does the following relational algebra expression represent?
∏courseId((∏studId(σsex="female"(studInfo))×∏courseId(enroll))−enroll)
A) Courses in which all the female students are enrolled
B) Courses in which a proper subset of female students are enrolled
C) Courses in which only male students are enrolled
D) None of the above
20. Consider the relation employee(name, sex, supervisorName) with name as the
key. supervisorName gives the name of the supervisor of the employee under consideration.
What does the following Tuple Relational Calculus query produce?
{e.name | employee(e) ∧ (∀x) [¬employee(x) ∨ x.supervisorName ≠ e.name ∨ x.sex = "male"]}
A) Names of employees with a male supervisor
B) Names of employees with no immediate male subordinates
C) Names of employees with no immediate female subordinates
D) Names of employees with a female supervisor
21. Consider the relations r1(P, Q, R) and r2(R, S, T) with primary keys P and R respectively. The
relation r1 contains 2000 tuples and r2 contains 2500 tuples. The maximum size of the join r1 ⋈ r2
is
A) 2000 B) 2500 C) 4500 D) 5000
22. Which of the following relational query languages have the same expressive power?
I) Relational algebra
II) Tuple relational calculus restricted to safe expressions
III) Domain relational calculus restricted to safe expressions
A) II & III B) I & II C) I & III D) I, III & III
23. Let r be a relation instance with schema R = (A, B, C, D). We
define r1=πA,B,C(r)r1=πA,B,C(r) and r1=πA,D(r)r1=πA,D(r). Let s=r1∗r2s=r1∗r2 where * denotes
natural join. Given that the decomposition of r into r1 and r2 is lossy, which one of the following is
TRUE?
A) s ⊂ r B) r ⋃ s = r C) r ⊂ s D) r * s = s
24. Let R1 (A, B, C) and R2 (D, E) be two relation schema, where the primary keys are shown
underlined, and let C be a foreign key in R1 referring to R2. Suppose there is no violation of the
above referential integrity constraint in the corresponding relation instances r1 and r2. Which one
of the following relational algebra expressions would necessarily produce an empty relation?

A) B) C) D)
25. Consider the following SQL query:
Select distinct a1, a2, ..., an
from r1, r2, ..., rm
where P;
For an arbitrary predicate P, this query is equivalent to which of the following relational algebra
expressions?

A) C)

B) D)
26. With regard to the expressive power of the formal relational query languages, which of the following
statements is true?
A) Relational Algebra is more powerful than relational calculus
B) Relational Algebra has same power as relational calculus
C) Relational Algebra has same power as safe relational calculus
D) None of the above
27. Given the relations: employee (name, salary, deptno), and department (deptno, deptname,
address). Which of the following queries cannot be expressed using the basic relational algebra
operations (σ , π , × ,⋈ , ∪ , ∩ , − )?
A) Department address of every employee
B) Employees whose name is the same as their department name
C) The sum of all employee's salaries
D) All emplyees of a given department
28. Consider the join of a relation R with a relation S. If R has m tuples and S has n tuples then the
maximum and minimum sizes of the join respectively are
A) m + n and 0
B) mn and 0
C) m + n and |m - n|
D) mn and m + n
29. The relational algebra expression equivalent to the following tuple calculus expression:
{t|t∈r∧(t[A]=10∧t[B]=20)} {t|t∈r∧(t[A]=10∧t[B]=20)} is:
A) Σ <A=10 ∨ B = 20> (r) C) Σ<A=10> (r) ∪ Σ<B=20>(r)
B) Σ<A=10> (r) ∩ Σ<B=20>(r) D) Σ<A=10> (r) - Σ<B=20>(r)
30. Consider the data given in above question. Which of the following is a correct attribute set for one
of the tables for the correct answer to the above question?

A) {M1, M2, M3, P1} B) {M1, P1, N1, N2} C) {M1, P1, N1} D) {M1, P1}

You might also like