MCQs / Computer Science / NSCT: Databases

NSCT: Databases MCQs — Computer Science (page 2)

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.

26. An attribute such as PhoneNumbers that can hold several values is:

  1. Derived
  2. Multivalued
  3. Composite key
  4. Atomic

Answer: B) Multivalued

Explanation: Shown as a double ellipse. Lesson 4.1 · Databases

Discuss this question

27. Which ACID property guarantees that committed changes survive a power failure?

  1. Consistency
  2. Atomicity
  3. Isolation
  4. Durability

Answer: D) Durability

Explanation: Logs make committed work permanent. Lesson 4.4 · Databases

Discuss this question

28. A query run twice in one transaction returns extra rows inserted by another transaction. This is a:

  1. Non-repeatable write
  2. Lost update
  3. Phantom read
  4. Dirty read

Answer: C) Phantom read

Explanation: New rows "appear" like phantoms. Lesson 4.4 · Databases

Discuss this question

29. CREATE, ALTER and DROP belong to:

  1. DCL
  2. TCL
  3. DML
  4. DDL

Answer: D) DDL

Explanation: Data Definition Language changes structure. Lesson 4.2 · Databases

Discuss this question

30. A cell containing "Math, Physics, CS" in a Subjects column violates:

  1. 3NF
  2. 1NF
  3. 2NF
  4. BCNF

Answer: B) 1NF

Explanation: The value is not atomic. Lesson 4.3 · Databases

Discuss this question

31. Table Order(OrderID, ProductID, ProductName, Qty) has key (OrderID, ProductID). ProductName depends only on ProductID. The table violates:

  1. 1NF
  2. 2NF
  3. None – it is fully normalized
  4. BCNF only

Answer: B) 2NF

Explanation: This is a partial dependency. Lesson 4.3 · Databases

Discuss this question

32. A transaction is:

  1. A backup file
  2. A logical unit of work that must complete fully or not at all
  3. A table
  4. A type of index

Answer: B) A logical unit of work that must complete fully or not at all

Explanation: e.g. a money transfer. Lesson 4.4 · Databases

Discuss this question

33. Which WHERE clause usually prevents the use of an index on column name?

  1. WHERE name LIKE 'Ali%'
  2. WHERE name IN ('Ali', 'Sara')
  3. WHERE name = 'Ali'
  4. WHERE name LIKE '%ali'

Answer: D) WHERE name LIKE '%ali'

Explanation: A leading wildcard forces a full scan. Lesson 4.5 · Databases

Discuss this question

34. A relation with a single-attribute primary key and no non-key attributes depending on each other is at least in:

  1. 3NF
  2. 2NF only
  3. 1NF only
  4. Not normalized

Answer: A) 3NF

Explanation: With a single-column key, partial dependency is impossible, and no transitive dependency means 3NF. Lesson 4.3 · Databases

Discuss this question

35. Splitting a large table's rows across several servers is called:

  1. Replication
  2. Indexing
  3. Normalization
  4. Sharding (horizontal partitioning)

Answer: D) Sharding (horizontal partitioning)

Explanation: Each shard holds a subset of rows. Lesson 4.5 · Databases

Discuss this question

36. Which clause filters groups after aggregation?

  1. WHERE
  2. HAVING
  3. GROUP BY
  4. ORDER BY

Answer: B) HAVING

Explanation: WHERE filters rows before grouping. Lesson 4.2 · Databases

Discuss this question

37. ETL in data warehousing stands for:

  1. Evaluate, Test, Launch
  2. Export, Translate, Link
  3. Encrypt, Transfer, Log
  4. Extract, Transform, Load

Answer: D) Extract, Transform, Load

Explanation: Data is cleaned and loaded into the warehouse. Lesson 4.5 · Databases

Discuss this question

38. Which query returns the second-highest salary?

  1. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp)
  2. SELECT MIN(salary) FROM emp
  3. SELECT salary FROM emp ORDER BY salary LIMIT 2
  4. SELECT MAX(salary) FROM emp

Answer: A) SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp)

Explanation: The subquery removes the top salary. Lesson 4.2 · Databases

Discuss this question

39. A shared (S) lock allows:

  1. Only the DBA to read
  2. Other transactions to read but not write the item
  3. Other transactions to write
  4. No other access at all

Answer: B) Other transactions to read but not write the item

Explanation: Exclusive (X) locks block both reads and writes. Lesson 4.4 · Databases

Discuss this question

40. Using the tables below, what does this query return? sql SELECT name FROM student WHERE city IN ('Karachi', 'Quetta') AND 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

  1. Ayesha, Zain, Ali
  2. Ayesha, Bilal
  3. Ayesha, Zain
  4. Ayesha

Answer: C) Ayesha, Zain

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

Discuss this question

41. Using the tables below, what does this query return? sql SELECT MAX(marks) - MIN(marks) FROM enrol; 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. 35
  2. 36
  3. 37
  4. 38

Answer: B) 36

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

Discuss this question

42. A CROSS JOIN of a table with 4 rows and a table with 5 rows returns:

  1. 5 rows
  2. 4 rows
  3. 20 rows
  4. 9 rows

Answer: C) 20 rows

Explanation: Every combination: 4 × 5. Lesson 4.2 · Databases

Discuss this question

43. The strongest SQL isolation level is:

  1. Read Committed
  2. Read Uncommitted
  3. Serializable
  4. Repeatable Read

Answer: C) Serializable

Explanation: It prevents dirty, non-repeatable and phantom reads. Lesson 4.4 · Databases

Discuss this question

44. UNION differs from UNION ALL because UNION:

  1. Sorts by primary key only
  2. Removes duplicate rows
  3. Keeps duplicates
  4. Works only on one table

Answer: B) Removes duplicate rows

Explanation: UNION ALL is faster as it skips duplicate removal. Lesson 4.2 · Databases

Discuss this question

45. The number of attributes (columns) in a relation is its:

  1. Arity of rows
  2. Cardinality
  3. Domain
  4. Degree

Answer: D) Degree

Explanation: Cardinality is the number of tuples. Lesson 4.1 · Databases

Discuss this question

46. Using the tables below, what does this query return? sql SELECT COUNT(DISTINCT city) 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

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

Answer: D) 4

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

Discuss this question

47. The logical order of execution of a SELECT query starts with:

  1. WHERE
  2. SELECT
  3. FROM
  4. ORDER BY

Answer: C) FROM

Explanation: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY. Lesson 4.2 · Databases

Discuss this question

48. Using the tables below, what does this query return? sql SELECT name FROM student WHERE cgpa IS NULL; 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. Hina
  2. NULL
  3. (no rows)
  4. Zain

Answer: D) Zain

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

Discuss this question

49. The main purpose of normalization is to:

  1. Encrypt data
  2. Increase redundancy
  3. Reduce redundancy and update anomalies
  4. Speed up network traffic

Answer: C) Reduce redundancy and update anomalies

Explanation: It organises tables logically. Lesson 4.3 · Databases

Discuss this question

50. The functional dependency RollNo → Name means:

  1. RollNo is a foreign key
  2. Each RollNo determines exactly one Name
  3. Names are unique
  4. Each Name determines one RollNo

Answer: B) Each RollNo determines exactly one Name

Explanation: Same roll number always gives the same name. Lesson 4.3 · Databases

Discuss this question

Previous Page 2 of 5 Next

Practise NSCT: Databases MCQs

More Computer Science chapters