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.
1. Keeping copies of the same database on several servers for availability is:
Sharding
Denormalization
Hashing
Replication
Answer: D) Replication
Explanation: Replicas can take over if one fails. Lesson 4.5 · Databases
5. Using the tables below, what does this query return? sql SELECT name FROM student WHERE cgpa BETWEEN 3.0 AND 3.5; 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
Ali, Bilal, Sara
Ali, Bilal
Ali
Ali, Zain
Answer: B) Ali, Bilal
Explanation: Running the query on the given data returns: Ali, Bilal. Lesson 4.2 · Databases
7. Using the tables below, what does this query return? sql SELECT MAX(cgpa) FROM student WHERE dept = 'SE'; 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
3.8
3.9
4
3.7
Answer: A) 3.8
Explanation: Running the query on the given data returns: 3.8. Lesson 4.2 · Databases
12. Using the tables below, what does this query return? sql SELECT UPPER(SUBSTR(name, 1, 3)) FROM student WHERE id = 6; 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
AYE
Aye
AYESHA
SHA
Answer: A) AYE
Explanation: Running the query on the given data returns: AYE. Lesson 4.2 · Databases
16. Using the tables below, what does this query return? sql SELECT name FROM student WHERE cgpa (SELECT AVG(cgpa) FROM student) ORDER BY name; 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
Ayesha, Hina, Sara
Ayesha, Hina, Zain
Ayesha, Hina
Ayesha, Hina, Sara, Ali
Answer: A) Ayesha, Hina, Sara
Explanation: Running the query on the given data returns: Ayesha, Hina, Sara. Lesson 4.2 · Databases
17. Using the tables below, what does this query return? sql SELECT COUNT() FROM student; 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
7
8
9
6
Answer: A) 7
Explanation: Running the query on the given data returns: 7. Lesson 4.2 · Databases
24. Using the tables below, what does this query return? sql SELECT dept, COUNT() FROM student GROUP BY dept HAVING COUNT() 2; 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
(CS, 3)
(no rows)
(CS, 3); (SE, 2)
(CS, 3); (SE, 2); (AI, 2)
Answer: A) (CS, 3)
Explanation: Running the query on the given data returns: (CS, 3). Lesson 4.2 · Databases