Chapter 3 — Quiz

14 questions. Answers and explanations at the bottom.


Multiple choice

Q1. In relational terms, a tuple is a: - A) Column - B) Row - C) Table - D) Constraint

Q2. Because a relation is a set, which is true? - A) Rows have a guaranteed, fixed order - B) Rows have no inherent order; use ORDER BY to impose one - C) Columns must be accessed by position - D) Duplicate rows are required

Q3. A candidate key is: - A) Any set of columns that is unique, even with extra columns - B) A minimal set of columns that uniquely identifies a row - C) Always an auto-generated integer - D) The same as a foreign key

Q4. The two rules of a primary key are: - A) Unique and indexed - B) Unique and never NULL - C) Numeric and auto-generated - D) Foreign and unique

Q5. A surrogate key is: - A) A key from the real-world data, like email or ISBN - B) An artificial identifier with no business meaning, generated by the database - C) A key that can be NULL - D) A composite of two natural keys

Q6. Referential integrity guarantees that: - A) Every column has a value - B) A foreign key value matches an existing primary key (or is NULL) - C) Rows are returned in order - D) Money is stored exactly

Q7. What does NULL mean? - A) Zero - B) An empty string - C) Unknown or absent - D) false

Q8. What does SELECT 5 = NULL; return? - A) true - B) false - C) NULL - D) An error

Q9. To find rows where phone has no value, you write: - A) WHERE phone = NULL - B) WHERE phone IS NULL - C) WHERE phone = '' - D) WHERE phone = 0

Q10. COUNT(phone) vs. COUNT(*) on customers: - A) Always equal - B) COUNT(phone) skips NULL phones, so it can be smaller - C) COUNT(*) skips NULLs - D) Both ignore NULLs equally

Q11. Which type should store money? - A) real - B) double precision - C) numeric(10,2) - D) float


True/False

Q12. A CHECK constraint lets you enforce a custom rule like rating BETWEEN 1 AND 5. (True / False)

Q13. Enforcing a rule with a database constraint is less reliable than enforcing it in each application. (True / False)


Short answer

Q14. Explain data independence and why it has helped SQL endure for decades.

---

Answer key

Q1 — B. A tuple is a row; an attribute is a column; a relation is a table.

Q2 — B. A relation is a set, so rows have no inherent order. Never rely on insertion order; use ORDER BY.

Q3 — B. A candidate key is a minimal superkey. {customer_id, email} is a superkey but not minimal (drop email and it's still unique).

Q4 — B. Unique and never null — together these are entity integrity. (A primary key is automatically indexed in PostgreSQL, but that's a side effect, not the definition.)

Q5 — B. A surrogate key is artificial and meaningless (Mercado's customer_id); a natural key comes from the data (email, ISBN).

Q6 — B. Referential integrity: a foreign key must reference an existing row (or be null, if nullable).

Q7 — C. Unknown or absent — not zero, empty string, or false.

Q8 — C. NULL. Comparing anything to an unknown yields unknown (NULL). This is three-valued logic.

Q9 — B. IS NULL. = NULL is never true, so option A returns nothing.

Q10 — B. COUNT(column) ignores NULLs; COUNT(*) counts rows. The difference is exactly the null phones.

Q11 — C. numeric (exact decimal). Floating-point types can't represent decimal fractions exactly and cause money drift.

Q12 — True. CHECK constraints enforce arbitrary boolean rules per row.

Q13 — False. A database constraint is enforced once, for every client and program, with no way around it — far more reliable than re-implementing the rule in each application.

Q14. Data independence is the separation of the logical model (relations, keys, constraints) from the physical storage (files, indexes, formats). Because queries reference only the logical model, the storage can change — new indexes, new internal formats, new hardware — without rewriting queries. That stability is a major reason SQL written decades ago still runs today.

Scoring: 12–14 excellent; 9–11 revisit keys and NULL; below 9, re-read the chapter — this vocabulary underlies everything ahead.