GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 156–160 of 185
Consider the following relational schema:
What does the following SQL query output?
Student(school-id,sch-roll-no,sname,saddress)
School(school-id,sch-name,sch-address,sch-phone)
Enrolment(school-id,sch-roll-no,erollno,examname)
ExamResult(erollno,examname,marks) What does the following SQL query output?
SELECT sch-name, COUNT (*)
FROM School C, Enrolment E, ExamResult R
WHERE E.school-id = C.school-id
AND
E.examname = R.examname AND E.erollno = R.erollno
AND
R.marks = 100 AND S.school-id IN (SELECT school-id
FROM student
GROUP BY school-id
HAVING COUNT (*) > 200)
GROUP By school-id Answer: (D)
The query has errors, so it does not run:
- The condition S.school-id IN (...) uses the alias S, but the FROM clause has only C, E and R. S is not defined.
- GROUP By school-id is ambiguous, because both School (C) and Enrolment (E) have a school-id column.
- sch-name is selected along with COUNT(*), but it is not in the GROUP BY. In standard SQL, every non-aggregate column in SELECT must appear in GROUP BY.
Any one of these makes the query fail, so options A, B and C, which describe an output, cannot be right.
Answer: (D)
- The condition S.school-id IN (...) uses the alias S, but the FROM clause has only C, E and R. S is not defined.
- GROUP By school-id is ambiguous, because both School (C) and Enrolment (E) have a school-id column.
- sch-name is selected along with COUNT(*), but it is not in the GROUP BY. In standard SQL, every non-aggregate column in SELECT must appear in GROUP BY.
Any one of these makes the query fail, so options A, B and C, which describe an output, cannot be right.
Answer: (D)
Let R (A, B, C, D, E, P, G) be a relational schema in which the following functional dependencies are known to hold:
and .
The relational schema R is
and .
The relational schema R is
Answer: (D)
Find the key. and appear on no right side, so both are in every key. : gives ; gives ; gives ; gives . So is all attributes and is the only candidate key. The prime attributes are ; all others, including , are non-prime.
: is a proper part of the key and is non-prime. This is a partial dependency, so R is not in 2NF.
Answer: (D)
: is a proper part of the key and is non-prime. This is a partial dependency, so R is not in 2NF.
Answer: (D)
Let be a relational schema in which the following functional dependencies are known to hold:
and .
The decomposition of into
and .
The decomposition of into
Answer: (A)
The given FDs are . Note that , so , and , so .
Lossless join:
- Join and : the common attribute is , and makes a key of . So this join is lossless and gives .
- Join and : the common attribute is , and holds, so is a key of . So this join is also lossless.
Dependency preserving:
- is in .
- is in .
- is in .
- is not in any one relation, but it follows from the kept FDs: holds in (it follows from and ), and holds in . So gives .
The decomposition is lossless and dependency preserving.
Answer: (A)
Lossless join:
- Join and : the common attribute is , and makes a key of . So this join is lossless and gives .
- Join and : the common attribute is , and holds, so is a key of . So this join is also lossless.
Dependency preserving:
- is in .
- is in .
- is in .
- is not in any one relation, but it follows from the kept FDs: holds in (it follows from and ), and holds in . So gives .
The decomposition is lossless and dependency preserving.
Answer: (A)
Consider the following relational schemes for a library database:
Book (Title, Author, Catalog_ no, Publisher, Year, Price)
Collection (Title,Author, Catalog_ no)
with in the following functional dependencies:
I. Title Author Catalog_no
II. Catalog_no Title Author Publisher Year
III. Publisher Title Year Price
Assume {Author, Title} is the key for both schemes. Which of the following statements is true?
Book (Title, Author, Catalog_ no, Publisher, Year, Price)
Collection (Title,Author, Catalog_ no)
with in the following functional dependencies:
I. Title Author Catalog_no
II. Catalog_no Title Author Publisher Year
III. Publisher Title Year Price
Assume {Author, Title} is the key for both schemes. Which of the following statements is true?
Answer: (C)
The key of both schemes is . The dependencies are:
I.
II.
III.
Collection (Title, Author, Catalog_no): Only I and II apply. In I the left side is a key. By II, covers Title and Author, so is also a key. Every left side is a superkey, so Collection is in BCNF, and BCNF implies 3NF. So "Collection is in 3NF" is true.
Book (Title, Author, Catalog_no, Publisher, Year, Price): The candidate keys are and . The non-prime attributes are Publisher, Year and Price.
- 2NF: Title alone and Author alone are not the left side of any FD, so no part of a key decides a non-prime attribute. There is no partial dependency, so Book is in 2NF.
- 3NF: in III, is not a superkey and Price is non-prime. So Book is not in 3NF (Price depends on the key through Publisher and Year).
So Book is in 2NF and Collection is in 3NF. Option (A) is wrong because Book is not in BCNF. Option (B) is wrong because Book is not in 3NF. Option (D) says "2NF only", which is wrong for Collection, since it is in 3NF.
Answer: (C)
I.
II.
III.
Collection (Title, Author, Catalog_no): Only I and II apply. In I the left side is a key. By II, covers Title and Author, so is also a key. Every left side is a superkey, so Collection is in BCNF, and BCNF implies 3NF. So "Collection is in 3NF" is true.
Book (Title, Author, Catalog_no, Publisher, Year, Price): The candidate keys are and . The non-prime attributes are Publisher, Year and Price.
- 2NF: Title alone and Author alone are not the left side of any FD, so no part of a key decides a non-prime attribute. There is no partial dependency, so Book is in 2NF.
- 3NF: in III, is not a superkey and Price is non-prime. So Book is not in 3NF (Price depends on the key through Publisher and Year).
So Book is in 2NF and Collection is in 3NF. Option (A) is wrong because Book is not in BCNF. Option (B) is wrong because Book is not in 3NF. Option (D) says "2NF only", which is wrong for Collection, since it is in 3NF.
Answer: (C)
Consider a file of 16384 records. Each record is 32 bytes long and its key field is of size 6 bytes. The file is ordered on a non-key field, and the file organization is unspanned. The file is stored in a file system with block size 1024 bytes, and the size of a block pointer is 10 bytes. If the secondary index is built on the key field of the file, and a multi-level index scheme is used to store the secondary index, the number of first-level and second-level blocks in the multi-level index are respectively
Answer: (C)
Each index entry is a key and a block pointer: bytes. With unspanned blocks, a block holds entries.
First level: the index is on a key field and the file is not ordered on it, so it is a secondary index and must be dense: one entry for each of the 16384 records.
Blocks =
Second level: one entry for each first-level block, so 256 entries.
Blocks =
So the first and second levels have 256 and 4 blocks.
Answer: (C)
First level: the index is on a key field and the file is not ordered on it, so it is a secondary index and must be dense: one entry for each of the 16384 records.
Blocks =
Second level: one entry for each first-level block, so 256 entries.
Blocks =
So the first and second levels have 256 and 4 blocks.
Answer: (C)