pbPassingBI
/
14 questions

Foundations & querying — quiz

14 questions covering this module. Relational concepts, SELECT, filtering, sorting, nulls and duplicates.

  1. What makes a column a primary key?

    1. It is the first column
    2. It uniquely identifies each row and is never null
    3. It is numeric
    4. It is indexed

    Answer: It uniquely identifies each row and is never null — Uniqueness and not-null are the defining properties.

  2. orders.customer_id referencing customers.customer_id is:

    1. A primary key
    2. A foreign key
    3. An index
    4. A constraint violation

    Answer: A foreign key — A column pointing at another table's primary key is a foreign key.

  3. Why avoid SELECT * in production queries?

    1. It is slower to type
    2. It breaks silently when the table structure changes
    3. It is not valid SQL
    4. It cannot be used with WHERE

    Answer: It breaks silently when the table structure changes — It also moves unneeded data and hides intent.

  4. Which correctly renames a column?

    1. SELECT name = customer_name
    2. SELECT name AS customer_name
    3. SELECT name 'customer_name'
    4. RENAME name TO customer_name

    Answer: SELECT name AS customer_name — AS is the standard alias syntax. Single quotes denote string values.

  5. BETWEEN 100 AND 500 includes:

    1. 101 to 499
    2. 100 to 500
    3. 100 to 499
    4. 101 to 500

    Answer: 100 to 500 — BETWEEN is inclusive on both endpoints.

  6. Which LIKE pattern can use an index?

    1. LIKE '%son'
    2. LIKE 'Jo%'
    3. LIKE '%ann%'
    4. None of them

    Answer: LIKE 'Jo%' — Only a trailing wildcard allows a seek; a leading one forces a scan.

  7. city = 'A' OR city = 'B' AND total > 100 returns:

    1. All A and B rows over 100
    2. All A rows, plus B rows over 100
    3. Only B rows over 100
    4. An error

    Answer: All A rows, plus B rows over 100 — AND binds tighter, so it groups with the B condition.

  8. How do you force OR to evaluate first?

    1. Write it first
    2. Use parentheses
    3. Use NOT
    4. It always does

    Answer: Use parentheses — Parentheses override the default precedence.

  9. Why can ORDER BY use a SELECT alias when WHERE cannot?

    1. Aliases are strings
    2. ORDER BY is evaluated after SELECT
    3. WHERE only takes columns
    4. It is a syntax quirk

    Answer: ORDER BY is evaluated after SELECT — Logical processing order: WHERE runs second, SELECT fifth, ORDER BY seventh.

  10. SQL Server's equivalent of LIMIT 10 is:

    1. LIMIT 10
    2. TOP 10
    3. ROWNUM <= 10
    4. FIRST 10

    Answer: TOP 10 — SQL Server uses TOP; Oracle uses FETCH FIRST or ROWNUM.

  11. Which correctly finds rows with no email?

    1. WHERE email = NULL
    2. WHERE email IS NULL
    3. WHERE email = ''
    4. WHERE NOT email

    Answer: WHERE email IS NULL — NULL cannot be compared with =; IS NULL is the test.

  12. AVG over 10 rows where 3 are null divides by:

    1. 10
    2. 7
    3. 3
    4. It errors

    Answer: 7 — Aggregates ignore nulls, so the divisor is the non-null count.

  13. SELECT DISTINCT city, state returns:

    1. Unique cities only
    2. Each unique city-state combination
    3. Unique states only
    4. An error

    Answer: Each unique city-state combination — DISTINCT operates on the full row combination.

  14. A query suddenly returns duplicates. Best first step?

    1. Add DISTINCT
    2. Check whether a join is fanning out rows
    3. Add LIMIT
    4. Add GROUP BY

    Answer: Check whether a join is fanning out rows — DISTINCT hides the symptom while any SUM stays double-counted.