MCQs / Computer Science / NSCT: Databases

NSCT: Databases MCQs — Computer Science (page 4)

112 multiple-choice questions on NSCT: Databases from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

76. Using the tables below, what does this query return? sql SELECT COUNT() FROM (SELECT city FROM student UNION ALL SELECT city FROM student WHERE dept = 'AI'); student id name dept cgpa city --------------- 1 Ali CS 3.4 Lahore 2 Sara SE 3.8 Karachi 3 Usman CS 2.9 Lahore 4 Hina AI 3.6 Islamabad 5 Bilal SE 3.1 Lahore 6 Ayesha CS 3.9 Karachi 7 Zain AI NULL Quetta

  1. 10
  2. 8
  3. 9
  4. 11

Answer: C) 9

Explanation: Running the query on the given data returns: 9. Lesson 4.2 · Databases

Discuss this question

77. MongoDB is an example of a:

  1. Document database
  2. Graph database
  3. Relational database
  4. Key-value cache only

Answer: A) Document database

Explanation: It stores JSON-like documents. Lesson 4.5 · Databases

Discuss this question

78. An INNER JOIN returns:

  1. All rows from both tables
  2. The Cartesian product
  3. All rows from the left table
  4. Only rows that have matches in both tables

Answer: D) Only rows that have matches in both tables

Explanation: Unmatched rows are excluded. Lesson 4.2 · Databases

Discuss this question

79. COUNT(column) differs from COUNT() because COUNT(column):

  1. Counts duplicates twice
  2. Ignores NULL values in that column
  3. Counts only distinct values
  4. Is faster always

Answer: B) Ignores NULL values in that column

Explanation: COUNT() counts all rows. Lesson 4.2 · Databases

Discuss this question

80. Candidate keys that are not chosen as the primary key are called:

  1. Alternate keys
  2. Partial keys
  3. Super keys
  4. Foreign keys

Answer: A) Alternate keys

Explanation: They could have been the primary key. Lesson 4.1 · Databases

Discuss this question

81. Using the tables below, what does this query return? sql SELECT ROUND(AVG(cgpa), 2) FROM student WHERE dept = 'CS'; student id name dept cgpa city --------------- 1 Ali CS 3.4 Lahore 2 Sara SE 3.8 Karachi 3 Usman CS 2.9 Lahore 4 Hina AI 3.6 Islamabad 5 Bilal SE 3.1 Lahore 6 Ayesha CS 3.9 Karachi 7 Zain AI NULL Quetta

  1. 3.4
  2. 3.5
  3. 3.6
  4. 3.3

Answer: A) 3.4

Explanation: Running the query on the given data returns: 3.4. Lesson 4.2 · Databases

Discuss this question

82. Table Student(RollNo, Name, DeptID, DeptName) has key RollNo, and DeptID → DeptName. The table is in 2NF but violates:

  1. 2NF
  2. 3NF
  3. No normal form
  4. 1NF

Answer: B) 3NF

Explanation: RollNo → DeptID → DeptName is transitive. Lesson 4.3 · Databases

Discuss this question

83. BASE in NoSQL systems emphasises:

  1. Strict serializability
  2. Eventual consistency
  3. Fixed schemas
  4. Two-phase commit

Answer: B) Eventual consistency

Explanation: Basically Available, Soft state, Eventually consistent. Lesson 4.5 · Databases

Discuss this question

84. Using the tables below, what does this query return? sql SELECT COUNT() FROM student s JOIN enrol e ON s.id = e.sid; student id name dept cgpa city --------------- 1 Ali CS 3.4 Lahore 2 Sara SE 3.8 Karachi 3 Usman CS 2.9 Lahore 4 Hina AI 3.6 Islamabad 5 Bilal SE 3.1 Lahore 6 Ayesha CS 3.9 Karachi 7 Zain AI NULL Quetta enrol (sid, code, marks): (1, CS101, 78), (1, CS201, 65), (2, CS201, 88), (3, CS101, 55), (4, AI401, 91), (6, CS201, 72), (6, CS301, 80), (5, CS101, 60) course (code, title, credits): (CS101, Programming, 4), (CS201, Databases, 3), (CS301, Networks, 3), (AI401, Machine Learning, 3)

  1. 8
  2. 10
  3. 9
  4. 7

Answer: A) 8

Explanation: Running the query on the given data returns: 8. Lesson 4.2 · Databases

Discuss this question

85. A table is in 1NF when:

  1. Every column contains atomic values
  2. It has no foreign keys
  3. It has no NULLs
  4. It has a composite key

Answer: A) Every column contains atomic values

Explanation: No repeating groups or multi-valued cells. Lesson 4.3 · Databases

Discuss this question

86. A primary key must be:

  1. Unique but may be null
  2. Repeated
  3. A text column
  4. Unique and not null

Answer: D) Unique and not null

Explanation: It identifies each row exactly. Lesson 4.1 · Databases

Discuss this question

87. Write-ahead logging means:

  1. Logs are optional
  2. Data is written before the log
  3. Only reads are logged
  4. Log records are written to stable storage before the data changes

Answer: D) Log records are written to stable storage before the data changes

Explanation: It allows undo and redo after a crash. Lesson 4.4 · Databases

Discuss this question

88. OLAP systems are designed for:

  1. Complex analysis and reporting
  2. Fast day-to-day transactions
  3. Storing passwords
  4. Network routing

Answer: A) Complex analysis and reporting

Explanation: OLTP handles daily transactions. Lesson 4.5 · Databases

Discuss this question

89. Using the tables below, what does this query return? sql SELECT COUNT() FROM (SELECT city FROM student UNION SELECT city FROM student WHERE dept = 'AI'); student id name dept cgpa city --------------- 1 Ali CS 3.4 Lahore 2 Sara SE 3.8 Karachi 3 Usman CS 2.9 Lahore 4 Hina AI 3.6 Islamabad 5 Bilal SE 3.1 Lahore 6 Ayesha CS 3.9 Karachi 7 Zain AI NULL Quetta

  1. 6
  2. 4
  3. 3
  4. 5

Answer: B) 4

Explanation: Running the query on the given data returns: 4. Lesson 4.2 · Databases

Discuss this question

90. The ability to change the physical storage of data without changing application programs is:

  1. Logical data independence
  2. Data redundancy
  3. Physical data independence
  4. Referential integrity

Answer: C) Physical data independence

Explanation: The three-schema architecture provides it. Lesson 4.1 · Databases

Discuss this question

91. A column in one table that refers to the primary key of another table is a:

  1. Candidate key
  2. Foreign key
  3. Super key
  4. Surrogate key

Answer: B) Foreign key

Explanation: It enforces referential integrity. Lesson 4.1 · Databases

Discuss this question

92. Which condition correctly finds rows where email is missing?

  1. WHERE email IS NULL
  2. WHERE email = NULL
  3. WHERE email IN NULL
  4. WHERE email == NULL

Answer: A) WHERE email IS NULL

Explanation: Comparisons with NULL using = are never true. Lesson 4.2 · Databases

Discuss this question

93. A minimal set of attributes that uniquely identifies a tuple is a:

  1. Foreign key
  2. Super key
  3. Composite attribute
  4. Candidate key

Answer: D) Candidate key

Explanation: A candidate key has no unnecessary attributes. Lesson 4.1 · Databases

Discuss this question

94. Which index type supports range queries such as salary BETWEEN 30000 AND 50000 well?

  1. B+ tree index
  2. Bitmap of primary key only
  3. Hash index
  4. No index can

Answer: A) B+ tree index

Explanation: B+ tree leaves are linked in sorted order. Lesson 4.5 · Databases

Discuss this question

95. The CAP theorem states that a distributed database can guarantee at most two of:

  1. Capacity, Accuracy, Privacy
  2. Consistency, Availability, Partition tolerance
  3. Clustering, Aggregation, Partitioning
  4. Concurrency, Atomicity, Performance

Answer: B) Consistency, Availability, Partition tolerance

Explanation: Network partitions force a trade-off. Lesson 4.5 · Databases

Discuss this question

96. Reading data written by another transaction that has not yet committed is a:

  1. Deadlock
  2. Phantom read
  3. Lost update
  4. Dirty read

Answer: D) Dirty read

Explanation: If that transaction rolls back, the data never existed. Lesson 4.4 · Databases

Discuss this question

97. Using the tables below, what does this query return? sql SELECT name FROM student WHERE cgpa 3.5 ORDER BY cgpa DESC; student id name dept cgpa city --------------- 1 Ali CS 3.4 Lahore 2 Sara SE 3.8 Karachi 3 Usman CS 2.9 Lahore 4 Hina AI 3.6 Islamabad 5 Bilal SE 3.1 Lahore 6 Ayesha CS 3.9 Karachi 7 Zain AI NULL Quetta

  1. Ayesha, Sara
  2. Ayesha, Sara, Hina, Ali
  3. Ayesha, Sara, Zain
  4. Ayesha, Sara, Hina

Answer: D) Ayesha, Sara, Hina

Explanation: Running the query on the given data returns: Ayesha, Sara, Hina. Lesson 4.2 · Databases

Discuss this question

98. If changing a department name requires updating many rows, the table suffers from:

  1. A deletion anomaly
  2. An update anomaly
  3. A deadlock
  4. An insertion anomaly

Answer: B) An update anomaly

Explanation: Redundant copies must all be changed. Lesson 4.3 · Databases

Discuss this question

99. A relation is in BCNF if, for every functional dependency X → Y:

  1. There are no keys
  2. X is a super key
  3. Y is a key
  4. X is a non-key attribute

Answer: B) X is a super key

Explanation: BCNF is a stricter form of 3NF. Lesson 4.3 · Databases

Discuss this question

100. An auto-incrementing ID column added only to identify rows is a:

  1. Surrogate key
  2. Foreign key
  3. Natural key
  4. Candidate key from data

Answer: A) Surrogate key

Explanation: It has no business meaning. Lesson 4.1 · Databases

Discuss this question

Previous Page 4 of 5 Next

Practise NSCT: Databases MCQs

More Computer Science chapters