You are on page 1of 31

Fundamentals of Database systems

DSE 310
Practice-1
Solution:
A Primary Key is the minimal set of attributes of a table that
has the task to uniquely identify the rows, or we can say the
tuples of the given particular table.
✔ Minimal:
✔ Accessible
✔ Unique
✔ Not-Null

student_id={1,2,3,1,4}
student_id, name ={(1,ROHAN), (2, kARTHIKA),
(3,PINAKI),(1,ROHAN)}
student_id, course_id={(1,c1), (2,c1),(3,c2),(1,c2),(4,c2) }
….etc.
Q. In context of a database, identify the incorrect
statement:
1) There can be more than one superkeys.
2) A candidate key is the minimal superkey.
3) One of the candidate keys is designated as
primary key
4) Primary key is obtained by removing one of
the attributes from candidate keys.
Q. Consider the following statements regarding keys:
(I) SuperKey is an attribute or combination of attributes that
uniquely identify records in the RDMS table
(II) Candidate key is subset of superkeys
(III) All superkeys are candidate keys but vice-versa is not
true.

a) Only (I) is true


b) (I) and (III) are true
c) Only (II) is true
d) (I) and (II) are true.
Given the basic ER and relational models, which of
the following is INCORRECT?

(A) An attribute of an entity can have more than one


value
(B) An attribute of an entity can be composite
(C) In a row of a relational table, an attribute can
have more than one value
(D) In a row of a relational table, an attribute can
have exactly one value or a NULL value
Solution:
For union, intersection, difference both relations
should have same arity.

Ans: Natural Join operation


B and D attribute is common in both tables. Write all
combinations corresponding to common B and D
entities ((1,a) and (1,b)).
A relation r(A, B) in a relational database has 1200 tuples. The
attribute A has integer values ranging from 6 to 20, and the
attribute B has integer values ranging from 1 to 20. Assume that
the attributes A and B are independently distributed. The
estimated number of tuples in the output of σ(A>10)∨(B=18)(r) is
______
Solution :A relation r(A, B) in a relational database has 1200 tuples. The attribute A has integer values ranging
from 6 to 20, and the attribute B has integer values ranging from 1 to 20. Assume that the attributes A and B
are independently distributed. The estimated number of tuples in the output of σ(A>10)∨(B=18)(r) is ______

Probability of first condition satisfies, P(A) = 10/15


Probability of second condition satisfies, P(B) = 1/20
Probability of both condition satisfy, P(A∩B) = 10/15*1/20 (Because of independent.)
So, either first or second condition satisfy P(A∪B)
= P(A) + P(B) – P(A∩B)
= 10/15 + 1/20 – 10/15*1/20
= 0.6833
Therefore, estimated number of tuples in the output,
= 1200*0.6833
= 820
Answer: (i) {X2}, (ii) {X1}, (iii) {}
Sol. P.X P.Y P.Z R.Y R.V P.X P.Y P.Z R.Y R.V

X1 Y1 Z1 Y1 V1 X2 X4 Z4 Y1 V1

X1 Y1 Z1 Y3 V2 X2 X4 Z4 Y3 V2

X1 Y1 Z1 Y2 V3 X2 X4 Z4 Y2 V3

X1 Y1 Z1 Y2 V2 X2 X4 Z4 Y2 V2

X1 Y1 Z2 Y1 V1

X1 Y1 Z2 Y3 V2

X1 Y1 Z2 Y2 V3

X1 Y1 Z2 Y2 V2

X2 Y2 Z2 Y1 V1

X2 Y2 Z2 Y3 V2
Satisfying both
X2 Y2 Z2 Y2 V3
conditions Ans is X2
X2 Y2 Z2 Y2 V2
Sol ii:
Q.X Q.Y Q.T R.Y R.V Q.X Q.Y Q.T R.Y R.V
X2 Y1 2 Y1 V1 X3 Y3 1 Y1 V1
X2 Y1 2 Y3 V2 X3 Y3 1 Y3 V2
X2 Y1 2 Y2 V3 X3 Y3 1 Y2 V3
X2 Y1 2 Y2 V2 X3 Y3 1 Y2 V2
X1 Y2 5 Y1 V1

X1 Y2 5 Y3 V2

X1 Y2 5 Y2 V3

X1 Y2 5 Y2 V2 X1

X1 Y1 6 Y1 V1

X1 Y1 6 Y3 V2

X1 Y1 6 Y2 V3

X1 Y1 6 Y2 V2
For the following relation instance of CR(StudentName, CourseName), what are the tuples T1 and
T2 will contain.
For the following relation instance of CR(StudentName, CourseName), what are the tuples T1 and
T2 will contain.

T1 includes tuples {‘CA’,’CB’,’CC’}


T2 will have {‘SA’, ‘SC’, ‘SD’, ‘SF’}
Solution: Consider two tables R and S.
Take all possible combinations of primary keys for fair analysis.

R S
P Q R1 R2 R3 P Q S1 S2

a b 1 2 3 a b 20 22

c d 4 5 6 c d 40 42

e z 7 8 9 e y 50 56

v f 10 11 12 w f 70 74

q r 13 14 15 s t 80 90

P Q R1 R2 R3 S1 S2

a b 1 2 3 20 22 Ans: a and c
c d 4 5 6 40 42
R S
P P P

a a a Ans: a, c and e
Natural
c c c
Relation
e e e

v w

s R S
q
P Q P Q P Q

a b a b a b
Intersection c d
c d c d
e z e y Ans: a and c
v f w f
q r s t
P Q P Q P Q P Q P Q P Q
a b a b a b a b e z a b
c d c d c d c d v f c d
e z e z e y e z q r

v f v f w f v f

q r q r s t q r

It is equivalent to R∩S as it is R-(R-S).


Solve it using tables R and S.
Ans: a and c
Sol. employee dependent
Emp id Emp Emp Dep Eid Dep Dep Em Em Emp Dep Dep Dep
name age id Na Age p id p age id Nam Age
me na
1 A 20
me
11 1 EC 22
2 B 25
1 A 20 11 EC 22
3 C 21 22 1 IT 32
1 A 20 22 IT 32
4 D 50 33 2 CSE 42 2 B 25 33 CSE 42
5 E 60
55 3 BM 50 3 C 21 55 BM 50
5 E 60 99 ME 70
44 4 PHY 15

99 5 ME 70

Ans is D
All of his/her dependents

You might also like