🌍 SQL & Databases · flashcards
SQL & Databases Advanced SQL and Programmability Flashcards
50 question-and-answer cards covering Advanced SQL and Programmability as it is examined in SQL & Databases. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Advanced SQL and Programmability deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
How can you insert rows into a table from the result of a query?
INSERT INTO t (a, b) SELECT a, b FROM other_table WHERE condition;
What is the standard syntax for UPDATE with a join in PostgreSQL?
UPDATE t SET col = s.val FROM source s WHERE t.id = s.id; (PostgreSQL uses FROM; SQL Server uses UPDATE t SET ... FROM t JOIN source s ON ...).
Why is a WHERE clause critical in an UPDATE or DELETE statement?
Without WHERE, the operation applies to every row in the table, updating or deleting all rows unintentionally.
Compare DELETE and TRUNCATE across four dimensions: WHERE support, logging, triggers, and identity reset.
DELETE: supports WHERE, is row-by-row (fully logged), fires triggers, keeps identity seed. TRUNCATE: removes all rows, minimally logged/faster, no WHERE, usually fires no row triggers, and resets identity/auto-increment.
Is TRUNCATE typically DDL or DML, and what implication does that have?
TRUNCATE is generally treated as DDL. It is faster because it deallocates data pages rather than deleting rows individually, and in some databases it cannot be rolled back or is auto-committed.
What does UPSERT mean?
An operation that inserts a new row if it does not exist, or updates the existing row if a key conflict occurs ("update or insert"), performed atomically in one statement.
Write the PostgreSQL UPSERT syntax to insert into t(id, v) and update v on conflict.
INSERT INTO t (id, v) VALUES (1, 'a') ON CONFLICT (id) DO UPDATE SET v = EXCLUDED.v;
What is the MySQL equivalent of an UPSERT?
INSERT INTO t (id, v) VALUES (1,'a') ON DUPLICATE KEY UPDATE v = VALUES(v); (newer syntax uses an alias instead of VALUES()).
Which SQL Server statement provides UPSERT-style conditional insert/update/delete?
The MERGE statement, which matches a target against a source and runs WHEN MATCHED / WHEN NOT MATCHED clauses.
What does the PostgreSQL RETURNING clause do?
RETURNING lets an INSERT, UPDATE, or DELETE return columns from the affected rows (e.g., a generated id) without a separate SELECT: INSERT INTO t (v) VALUES ('a') RETURNING id;
What is SQL Server's equivalent of RETURNING, and how does it identify old vs new values?
The OUTPUT clause. It exposes the INSERTED pseudo-table (new values) and the DELETED pseudo-table (old values); UPDATE can reference both.
What is a view in SQL?
A named, stored query that acts as a virtual table. It stores no data itself (except materialized views); it re-runs its defining SELECT each time it is queried.
Write the syntax to create a view named active_users.
CREATE VIEW active_users AS SELECT id, name FROM users WHERE active = true;
Name three benefits of using views.
They simplify complex queries (reusable abstraction), provide security by exposing only selected columns/rows, and give a stable interface that hides underlying schema changes.
What conditions generally make a view updatable?
It must map to a single base table, with no aggregation (GROUP BY, HAVING), no DISTINCT, no window functions, no set operations (UNION), and typically no computed columns being modified — so each view row corresponds to exactly one base-table row.
What does WITH CHECK OPTION do on an updatable view?
It forces INSERTs and UPDATEs through the view to satisfy the view's WHERE condition, preventing rows from being modified so they would disappear from (or never appear in) the view.
How can you make a non-updatable view support modifications?
Define an INSTEAD OF trigger (INSTEAD OF INSERT/UPDATE/DELETE) that translates the DML on the view into the appropriate operations on the underlying base tables.
What is a materialized view and how does it differ from a regular view?
A materialized view physically stores the query's result set on disk, so reads are fast but data can be stale. A regular view stores only the query definition and recomputes results on each access (always current).
What are the two broad refresh strategies for materialized views?
Complete (full) refresh, which recomputes the entire result set, and incremental/fast refresh, which applies only the changes since the last refresh using logs. Refresh can be scheduled/on-demand or, in some systems, on commit.
How do you refresh a materialized view in PostgreSQL without locking out readers?
REFRESH MATERIALIZED VIEW CONCURRENTLY view_name; (requires a unique index on the materialized view).
What are procedural extensions to SQL, and give two examples by vendor.
Procedural extensions add imperative programming constructs (variables, loops, conditionals, error handling) to declarative SQL. Examples: Oracle PL/SQL, SQL Server T-SQL, PostgreSQL PL/pgSQL.
What is the difference between a stored procedure and a user-defined function?
A function must return a value and is usually callable within a query (often no side effects). A stored procedure is invoked with CALL/EXEC, can perform actions and return zero or many result sets, and typically cannot be embedded in a SELECT.
What are the three common parameter modes in procedural SQL, and what does each do?
IN passes a value into the routine (read-only), OUT returns a value back to the caller, and IN OUT (INOUT) passes a value in and returns a possibly modified value out.
By what two mechanisms can a routine return values to its caller?
Via a RETURN statement/value (functions and scalar returns) or via OUT / INOUT parameters. Procedures may also return result sets. RETURN also immediately exits the routine.
What this deck covers
The Advanced SQL and Programmability deck follows the SQL & Databases Advanced SQL and Programmability syllabus — 7 chapters and 26 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 7.1 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 161 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Advanced SQL and Programmability flashcards FAQ
How many Advanced SQL and Programmability flashcards are in this SQL & Databases deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these SQL & Databases flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Advanced SQL and Programmability cards cover?
They follow the SQL & Databases Advanced SQL and Programmability syllabus — 7 chapters and 26 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.