Prepstellar

SQL Fundamentals · Final test · 25 questions

SQL Fundamentals final test: 25 free questions

Untimed here · timed and scored in the app

A free SQL Fundamentals practice test with 25 questions drawn from the whole course. Answer at your pace and read why each option is right or wrong.

Swipe, scroll or use ← →
  1. Q1 / 25

    A read-only analytical query preserves sorted worker output, but it calls a user-defined function with no parallel label. Parallel workers are otherwise available. What prevents the desired plan?

    1. AGather Merge cannot be used for read-only queries
    2. BAvailable workers force the leader to stop participating
    3. CThe unlabeled function defaults to parallel unsafe
    4. DSorted output requires a data-modifying CTE
    Show the answer

    Unlabeled user-defined functions default to parallel unsafe, so worker availability and desired ordering cannot make the query parallel.

    Next → 1 / 25
  2. Q2 / 25

    An equality operator receives one non-null operand and one null operand. What does the expression yield?

    1. AAn error, because null cannot be compared
    2. BA plain false
    3. CNull, signifying unknown
    4. DTrue, because both sides are comparable
    Show the answer

    Ordinary comparison operators propagate the unknown, so the result is null rather than a decision, and a qualification that keeps only true conditions therefore drops the row; a definite false would need a predicate that treats null as a comparable value.

    Next → 2 / 25
  3. Q3 / 25

    Which statement about the `RENAME` forms of `ALTER TABLE` is correct?

    1. AThey may be listed alongside other alterations so that one pass over the table covers them all
    2. BThey rewrite each row so that it records the new name of its table
    3. CThey rename a parent table's column while leaving the descendant tables untouched
    4. DA rename changes only the name, and a renamed constraint's index is renamed too
    Show the answer

    A rename is a catalog change, which is why the data is untouched, and the index that backs a renamed constraint follows the constraint's new name.

    Next → 3 / 25
  4. Q4 / 25

    Which PostgreSQL JSON type preserves the exact input text, including insignificant whitespace and object-key order?

    1. Ajsonb
    2. Bjsonpath
    3. Cjson
    4. Dtext[]
    Show the answer

    The json type retains the original textual representation, while jsonb normalizes storage for processing.

    Next → 4 / 25
  5. Q5 / 25

    A ledger column stores monetary amounts that must be summed without accumulated rounding drift, and equality tests on stored balances must behave predictably. Reporting speed is a secondary concern. Which type fits?

    1. Anumeric, with a declared precision and scale
    2. Bbigint, storing the amount as whole units
    3. Cdouble precision, for its wider documented range
    4. Dreal, for its smaller per-value storage cost
    Show the answer

    Exactness is the deciding requirement, and numeric is the type the documentation recommends for monetary amounts, accepting that its calculations are slower; the floating-point types are documented as inexact, which is why equality tests on them can behave unexpectedly.

    Next → 5 / 25
  6. Q6 / 25

    After writing `FROM customer_accounts AS ca`, which reference to that source is valid later in the same query?

    1. A`account_id.customer_accounts`
    2. B`ca.account_id` in the select list
    3. C`customer_accounts.ca.account_id` in the same query
    4. D`customer_accounts.account_id`
    Show the answer

    The alias becomes the source name for the current query, so qualified references use `ca`.

    Next → 6 / 25
  7. Q7 / 25

    What comes after the central syntax and data-operation topics in the deeper documentation path?

    1. AA guarantee that PostgreSQL extensions work unchanged in every engine
    2. BRemoval of tables, clients, data types, and database connections
    3. CReplacement of SQL with fixed row positions and server filenames
    4. DIndexes, text search, concurrency, performance, and parallel query
    Show the answer

    The deeper path reaches operational reasoning only after syntax, definition, manipulation, queries, types, and functions.

    Next → 7 / 25
  8. Q8 / 25

    A product and its referenced supplier are independent business objects, the supplier column is `NOT NULL`, and deleting a supplier must not delete products. Which action is suitable?

    1. AUse `RESTRICT` or `NO ACTION` and handle both objects explicitly
    2. BUse `SET NULL` so each product remains with a null supplier
    3. CUse `CASCADE` so deleting the supplier also deletes every product
    4. DUse `SET DEFAULT` without ensuring the default references a supplier
    Show the answer

    Restrictive behavior suits independent objects and preserves the non-null child rows until the application makes an explicit valid change.

    Next → 8 / 25
  9. Q9 / 25

    What must match before an indexed comparison can use a chosen index method?

    1. AThe comparison must use every operator supported by the method
    2. BThe comparison value must reference another column in the indexed table
    3. CThe comparison operator must belong to the column's operator class
    4. DThe index name must contain the comparison operator's text
    Show the answer

    The operator class connects the indexed column to the specific operators that its access method can implement.

    Next → 9 / 25
  10. Q10 / 25

    An application repeatedly filters inside large JSON documents and does not need to preserve whitespace, key order, or duplicate object keys. Which storage choice best fits both requirements?

    1. AStore the documents as jsonb and use its indexing support
    2. BStore the documents as json to retain the original input representation
    3. CStore each document as text and reparse it for every filter
    4. DStore keys in an array so object order remains available
    Show the answer

    jsonb avoids repeated reparsing and supports indexing, while the discarded textual details are explicitly unnecessary.

    Next → 10 / 25
  11. Halfway, at your pace

    In the app the mock exam is timed and scored like the real thing.

  12. Q11 / 25

    A value must contain the text Dianne's horse, use the regular SQL string form, and avoid PostgreSQL escape or dollar-quote extensions. Which expression meets all constraints?

    1. A'Dianne''s horse'
    2. B"Dianne's horse"
    3. C$$Dianne's horse$$
    4. DE'Dianne\'s horse'
    Show the answer

    The regular form doubles the embedded apostrophe inside single-quote delimiters; the `E` and dollar-quoted forms are PostgreSQL extensions.

    Next → 11 / 25
  13. Q12 / 25

    What does scalar NOT IN return when its right-side subquery returns no rows?

    1. ANULL, because every empty subquery is unknown
    2. BAn error, because NOT IN requires one returned row
    3. CFalse, because no right-side value confirms inequality
    4. DTrue, because only unequal rows were found vacuously
    Show the answer

    The empty set contains no equal row and no NULL row, so the documented empty-subquery case for NOT IN is true.

    Next → 12 / 25
  14. Q13 / 25

    A read-only report runs several queries that must all use one view of the data, concurrent commits must not appear midway, and the report does not require its result to participate in a serial business-rule outcome. Which least demanding PostgreSQL level fits?

    1. ASerializable, because only dependency monitoring can keep query results unchanged
    2. BRead Uncommitted, reading concurrent work before it commits
    3. CRepeatable Read, using the database view fixed by its first query
    4. DRead Committed, taking a new database view for every report query
    Show the answer

    A transaction-stable view directly satisfies the multi-query requirement, while serial dependency monitoring is unnecessary for the stated reporting goal.

    Next → 13 / 25
  15. Q14 / 25

    Two joined sources both expose a column named `id`. What identifies the `id` from alias `c`?

    1. A`c AS id`
    2. B`id.c`
    3. C`id FROM c.id`
    4. D`c.id`
    Show the answer

    A qualified reference places the table name or alias before the column name.

    Next → 14 / 25
  16. Q15 / 25

    Which window function gives 1, 2, 3 and so on to the rows of a partition, handing a different number even to rows that tie?

    1. Arank, which numbers rows from one and repeats a number for ties
    2. Brow_number, which numbers the rows from one inside the partition
    3. Cdense_rank, which numbers peer groups rather than individual rows
    4. Dntile, which numbers the buckets the partition has been divided into
    Show the answer

    Only the plain numbering function gives every row a number of its own, since the ranking functions are defined to return the same answer for every row of a peer group.

    Next → 15 / 25
  17. Q16 / 25

    A learner must connect to an existing database, inspect current rows, and avoid confusing client help with a data request. Which sequence fits?

    1. ARun psql for the database, issue SELECT with a semicolon, and use backslash h only for client help
    2. BRename the cluster to psql, make a row the database, and query by closing the terminal
    3. COpen a table as the client, omit command termination, and use DELETE to display syntax help
    4. DCreate a server from SELECT, use INSERT as the client application, and treat every backslash command as database SQL
    Show the answer

    The sequence keeps connection, SQL retrieval, statement completion, and psql's internal help role distinct.

    Next → 16 / 25
  18. Q17 / 25

    What does `UNIQUE (a, c)` require?

    1. AEach value of `a` and each value of `c` must be unique separately
    2. BEach combination of `a` and `c` must be unique
    3. CAt least one of `a` or `c` must differ from every earlier row
    4. DThey must be the table's primary key
    Show the answer

    A multicolumn unique constraint protects the combined candidate-key value while allowing either component to repeat independently.

    Next → 17 / 25
  19. Q18 / 25

    Which statement defines a view named active_orders from a SELECT query?

    1. ACREATE TABLE VIEW active_orders AS SELECT ...
    2. BCREATE VIEW active_orders AS SELECT ...
    3. CCREATE VIEW active_orders FROM SELECT ...
    4. DVIEW active_orders USING SELECT ...
    Show the answer

    CREATE VIEW binds a relation name to the rows and columns produced by the following query.

    Next → 18 / 25
  20. Q19 / 25

    Which command is optimized to load many rows with less overhead than a series of INSERT commands?

    1. AANALYZE
    2. BVACUUM
    3. CEXPLAIN
    4. DCOPY
    Show the answer

    COPY is the documented bulk-loading command and is usually faster than batched INSERT.

    Next → 19 / 25
  21. Q20 / 25

    A nightly load re-sends rows that may already exist under a unique key. Existing rows must be refreshed with the incoming values, the run must be safe to repeat under concurrent activity, and no violation error may surface. Which clause meets the requirements?

    1. AA delete of the matching keys followed by a plain insert of the incoming rows
    2. BA conflict clause naming the unique key, with a skipping action
    3. CA conflict clause naming the unique key, with an updating action reading the proposed row
    4. DA conflict clause with no target, with an updating action reading the proposed row
    Show the answer

    Refreshing existing rows rules out the skipping action, the updating action requires a conflict target and reaches the incoming values through the special excluded name, and it is the action documented to guarantee an atomic insert-or-update outcome under high concurrency.

    Next → 20 / 25
  22. Q21 / 25

    A side-effect-free common table expression reads a large table and is referenced twice. Each reference needs a different small subset, and the underlying computation is cheap enough to repeat. Which choice favors applying both filters early?

    1. AUse NOT MATERIALIZED so each restriction can reach the base scan
    2. BUse a recursive term so each subset becomes a working table
    3. CUse UNION so duplicate rows replace parent restrictions
    4. DUse MATERIALIZED so the complete large result is calculated once
    Show the answer

    Merging permits each parent restriction to be applied directly, and the scenario accepts the possible duplicate computation cost.

    Next → 21 / 25
  23. Q22 / 25

    A Read Committed consistency check compares totals from two actively updated tables. Non-serializable writers must remain possible elsewhere, but this check needs one current view with no uncommitted table changes. Which design fits?

    1. ALock every table used by the check in `SHARE` mode or higher before reading
    2. BRun the two totals as successive plain queries with no explicit locks
    3. CMake only the check Serializable while other writers remain non-serializable
    4. DLock one returned row from each table after both totals are calculated
    Show the answer

    A global invariant needs table-scoped protection across all participating data when the environment permits writers outside a uniform serializable protocol.

    Next → 22 / 25
  24. Q23 / 25

    What fills left-side columns for an unmatched right row in a right outer join?

    1. AValues copied from the right-side key
    2. BZeros for numeric columns
    3. CThe previous matched row
    4. DNull values
    Show the answer

    A right join preserves that unmatched right row and null-extends the missing left side.

    Next → 23 / 25
  25. Q24 / 25

    Which call concatenates the values of column a with a comma and guarantees that the resulting text is in alphabetical order?

    1. Astring_agg(a ORDER BY a, ',')
    2. Bstring_agg(a, ',') with the query's own ORDER BY on a
    3. Cstring_agg(a, ',' ORDER BY a)
    4. Dstring_agg(a, ',') on its own, since input arrives in table order
    Show the answer

    The ordering clause of an aggregate goes after all of its arguments, which is why the delimiter is written first; ordering the query itself arranges output rows and leaves the order of the values reaching the aggregate untouched.

    Next → 24 / 25
  26. Q25 / 25

    What transferable habit should accompany PostgreSQL practice?

    1. AIdentify product extensions and verify dialect-specific details
    2. BAssume each PostgreSQL behavior is universal across SQL engines
    3. CTreat every SQL statement as a PostgreSQL server process
    4. DAvoid general relational ideas whenever PostgreSQL runs a query
    Show the answer

    The course joins general SQL reasoning with explicit recognition of PostgreSQL-specific syntax and behavior.

    Next → 25 / 25
  27. That’s the whole mock exam

    Every question you miss comes back exactly when you’re about to forget it.

How to use this mock exam

Sit all 25 questions in one go: the mix covers every domain in the same proportion as the exam, so a low score points at the domain you skipped rather than at bad luck.

Read the explanation under every question, including the ones you got right — the reason an option is wrong is usually the thing being tested.

Then retake it in the app, where the mock exam is timed and scored and the questions you miss come back on a schedule.

The whole course, on your phone

Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.