SQL · Databases
43 questions · asked in 23 of 27 years (2000–2026)
MCQ 34 · MSQ 1 · NAT 81-mark 26 · 2-mark 17
2000Questions per year2026
Questions 41–43 of 43
Consider a relation geq which represents "greater than or equal to", that is, (x,y) geq only if yx:
create table geq
(
ib integer not null
ub integer not null
primary key ib
foreign key (ub) references geq on delete cascade
) Which of the following is possible if a tuple (x,y) is deleted ?Answer: (C)
Each tuple of geq has . is the primary key, so no two tuples have the same first value. is a foreign key to with on delete cascade, so deleting a tuple also deletes every tuple whose equals the deleted , and so on down the chain.
Delete .
- Level 1: tuples with are deleted. Here , and because is already used by . So .
- Level 2: tuples with are deleted. Here the second value is .
So a deleted tuple with is possible, which is option C.
Every cascaded tuple has , so a tuple with is never deleted. That rules out B, and also A, because makes even larger than . D is wrong because cascade lets the deletion go through.
Answer: (C)
Delete .
- Level 1: tuples with are deleted. Here , and because is already used by . So .
- Level 2: tuples with are deleted. Here the second value is .
So a deleted tuple with is possible, which is option C.
Every cascaded tuple has , so a tuple with is never deleted. That rules out B, and also A, because makes even larger than . D is wrong because cascade lets the deletion go through.
Answer: (C)
In SQL, relations can contain null values, and comparisons with null values are treated as unknown. Suppose all comparisons with a null value are treated as false. Which of the following pairs is not equivalent?
Answer: (C)
Treat every comparison with NULL as false. Then check each pair for , and (T = true, F = false):
For NULL, the comparison is false. But is false, so is true. So the pair in C differs for NULL.
Pair A matches because is the same as . Pair B matches because an integer with must be 5, and both sides are false for NULL.
Answer: (C)
For NULL, the comparison is false. But is false, so is true. So the pair in C differs for NULL.
Pair A matches because is the same as . Pair B matches because an integer with must be 5, and both sides are false for NULL.
Answer: (C)
Given relations r(w, x) and s(y, z) the result of
select distinct w, x from r, s
is guaranteed to be same as r, provided.
Answer: (A)
The cross product repeats every tuple of once for each tuple of . If is empty, the product is empty. select distinct w, x keeps the columns of and removes duplicate rows.
So the result is the same as only when is non-empty (so no tuple of is lost) and has no duplicates (because distinct would remove them). In SQL a relation can hold duplicates, since it is a multiset.
(A) gives exactly these two conditions.
(B) is wrong: if is empty, the result is empty, and this can differ from .
(C) is wrong for the same reason, and also because may have duplicates, which distinct removes.
(D) is wrong: equal numbers of tuples do not stop from having duplicates, which distinct would remove.
Answer: (A)
So the result is the same as only when is non-empty (so no tuple of is lost) and has no duplicates (because distinct would remove them). In SQL a relation can hold duplicates, since it is a multiset.
(A) gives exactly these two conditions.
(B) is wrong: if is empty, the result is empty, and this can differ from .
(C) is wrong for the same reason, and also because may have duplicates, which distinct removes.
(D) is wrong: equal numbers of tuples do not stop from having duplicates, which distinct would remove.
Answer: (A)
Keep practising