Quick Revision

GK One-Line Question & Answer

15541+ short questions with short answers, covering every category and sub-category on the site — no long articles to scroll through. Good for a fast recap before an exam, or a few minutes of daily practice.

DBMS → Functional Dependency 5

Given the FDs F={A to B, B to C, C to D, D to A} what is the canonical cover Fc?
Fc = A to B, B to C, C to D, D to A - each FD is individually necessary (no FD is derivable from the others) since removing any one breaks the cycle
click to copy
What is an independent set of FDs and why is it important?
A set of FDs where none of them can be derived from the others - important because it means each FD adds genuine new information about the schema and removing any one would change the closure F+
click to copy
What is the key lemma used to prove that Armstrongs axioms are sound?
For soundness: Reflexivity holds trivially by definition. Augmentation: if t1[X]=t2[X] then t1[XZ]=t2[XZ] which implies t1[Y]=t2[Y] gives t1[YZ]=t2[YZ]. Transitivity: if t1[X]=t2[X] implies t1[Y]=t2[Y] and t1[Y]=t2[Y] implies t1[Z]=t2[Z] then t1[X]=t2[X] implies t1[Z]=t2[Z]
click to copy
What is the chase algorithm used for in relational theory?
Testing whether a decomposition has the lossless join property and whether functional dependencies are preserved by applying FDs to a canonical table (tableau)
click to copy
What is the concept of dependency basis in the context of MVDs?
For a set of attributes X the dependency basis is the finest partition of (R-X) such that X multidetermines each block; this partitions the other attributes into independent groups that X independently multidetermines
click to copy

DBMS → SQL Basics 29

What is the correct logical execution order of SQL clauses in a SELECT statement?
FROM WHERE GROUP BY HAVING SELECT ORDER BY LIMIT
click to copy
What is the difference between WHERE and HAVING clauses in SQL?
WHERE filters individual rows BEFORE grouping; HAVING filters groups AFTER GROUP BY and aggregation - HAVING can reference aggregate functions, WHERE cannot
click to copy
What does the SQL clause NULLIF(expr1, expr2) return?
NULL if expr1 equals expr2 (returns expr1 otherwise); used to avoid division-by-zero errors: NULLIF(count, 0) returns NULL instead of causing error when count=0
click to copy
What is the behavior of aggregate functions (SUM, AVG, COUNT, MAX, MIN) with respect to NULL values?
Aggregate functions (except COUNT(*)) IGNORE NULL values - COUNT(*) counts all rows including NULLs; COUNT(column) counts only non-NULL values
click to copy
What is the purpose of the SQL WITH clause (Common Table Expression - CTE)?
To define named temporary result sets that can be referenced multiple times within a query improving readability and enabling recursive queries (WITH RECURSIVE)
click to copy
What is the difference between CHAR(n) and VARCHAR(n) data types?
CHAR(n) is fixed-length (always uses n bytes, padded with spaces if shorter); VARCHAR(n) is variable-length (uses only the space needed plus 1-2 bytes for length storage)
click to copy
What does the SQL CASE expression return when no WHEN condition matches and no ELSE clause is specified?
It returns NULL (the CASE expression evaluates to NULL when no WHEN matches and no ELSE is provided)
click to copy
What is a correlated subquery in SQL and how does it differ from a non-correlated subquery?
A subquery that references a column from the outer query causing it to be executed once for each row of the outer query (vs. non-correlated subquery which executes once independently)
click to copy
What is the SQL EXISTS operator and when should it be preferred over IN?
EXISTS returns TRUE if a subquery returns at least one row (stops at first match), preferred over IN when the subquery could return NULLs (IN with NULL has counterintuitive behavior) or when checking existence is more efficient
click to copy
What does SELECT * FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location = NULL) return?
An empty result set - the condition WHERE location = NULL is always FALSE (must use IS NULL instead of = NULL)
click to copy
What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER() window functions?
ROW_NUMBER(): unique sequential number with no gaps or ties; RANK(): same rank for ties then skips numbers (1,1,3); DENSE_RANK(): same rank for ties no gaps (1,1,2)
click to copy
What are LEAD() and LAG() window functions used for?
Accessing values from subsequent rows (LEAD) or preceding rows (LAG) within the result partition useful for computing differences between consecutive rows without self-joins
click to copy
What is the OVER(PARTITION BY...ORDER BY...ROWS/RANGE BETWEEN...) clause used for?
Defining the window frame for window functions - specifying which rows to include in each computation relative to the current row
click to copy
What is the SQL PIVOT operation conceptually and how is it typically implemented?
Transforming row values into column headers converting a narrow table into a wide table - implemented via conditional aggregation (CASE + GROUP BY) in standard SQL
click to copy
What is the COALESCE(expr1, expr2, ..., exprN) function?
Returns the first non-NULL expression from left to right - short-circuits (stops evaluating) once a non-NULL value is found
click to copy
What does the SQL FETCH FIRST n ROWS ONLY clause do and which standard introduced it?
It limits the result set to the first n rows (equivalent to LIMIT n in MySQL/PostgreSQL), introduced by SQL:2008 standard
click to copy
What is the SQL MERGE statement (also called UPSERT) used for?
Performing INSERT, UPDATE, or DELETE operations in a single statement based on whether a match exists between source and target tables - useful for ETL and synchronization operations
click to copy
What is three-valued logic (3VL) in SQL and what are the three truth values?
TRUE, FALSE, and UNKNOWN - where UNKNOWN results from comparisons involving NULL values; logical operations follow specific rules: TRUE AND UNKNOWN = UNKNOWN, FALSE AND UNKNOWN = FALSE, TRUE OR UNKNOWN = TRUE
click to copy
What is the difference between TRUNCATE and DELETE without a WHERE clause in SQL?
TRUNCATE removes all rows without logging individual row deletions (faster, minimal logging, resets auto-increment), cannot be rolled back in some DBMS, and cannot have triggers. DELETE logs each row deletion (slower, fully transactional, triggers fire, can be rolled back)
click to copy
In SQL what does DISTINCT do when used inside an aggregate function like COUNT(DISTINCT column)?
It counts only unique non-NULL values of the column eliminating duplicates before counting - e.g. COUNT(DISTINCT dept_id) counts how many distinct departments have employees
click to copy
What is the purpose of SQL CHECK constraint and what are its limitations?
To enforce a condition that must be true for all rows in a table; limitations include: cannot reference other tables, cannot contain subqueries in standard SQL, and in some DBMS it was parsed but not enforced
click to copy
What does SELECT DISTINCT department_id FROM employees return differently from SELECT department_id FROM employees GROUP BY department_id?
DISTINCT returns unique values without aggregation capability; GROUP BY allows adding aggregate functions. However, for just listing unique values with no aggregation, they produce identical results - GROUP BY is more powerful but DISTINCT is cleaner for simple deduplication
click to copy
What is the BETWEEN operator in SQL and is it inclusive or exclusive of boundaries?
BETWEEN a AND b is INCLUSIVE of both endpoints - equivalent to >= a AND <= b (both a and b are included in the range)
click to copy
What is the SQL LIKE operator, and what do the wildcards % and _ represent?
% matches zero or more characters (any sequence); _ matches exactly one character (any single character) - used for pattern matching in strings
click to copy
What is the difference between INNER JOIN and CROSS JOIN in SQL?
INNER JOIN returns only rows with matching values in both tables based on a join condition; CROSS JOIN returns the Cartesian product (every combination of rows from both tables, no join condition)
click to copy
What is a recursive CTE (WITH RECURSIVE) in SQL and what problem does it solve?
A CTE that references itself enabling traversal of hierarchical/graph data (like org charts, bill of materials, file systems) without knowing the depth in advance - queries tree/graph structures iteratively until no more rows are added
click to copy
What is a window function in SQL and how does it differ from aggregate functions?
Window functions perform calculations across a set of rows related to the current row without collapsing them into a single result row - unlike aggregate functions which collapse groups into single rows
click to copy
What is the difference between a subquery and a derived table (inline view) in SQL?
A subquery is any query nested within another query; a derived table (inline view) is specifically a subquery in the FROM clause that acts as a named temporary table for the outer query - derived tables require an alias
click to copy
What is the SQL HAVING clause and why is it necessary (can WHERE replace it)?
HAVING filters groups after GROUP BY aggregation and can reference aggregate function results (e.g. HAVING COUNT(*) > 5); WHERE cannot reference aggregate functions because it runs before aggregation - HAVING is necessary for filtering based on aggregated data
click to copy

DBMS → DDL Commands 6

What is the difference between DROP TABLE and TRUNCATE TABLE?
DROP TABLE is DDL - removes the table structure, all data, indexes, triggers, and constraints permanently; TRUNCATE TABLE is DDL in most DBMS - removes all data but preserves the table structure, indexes, and column definitions
click to copy
What does ON DELETE CASCADE in a FOREIGN KEY constraint specify?
When a referenced row in the parent table is deleted, automatically delete all corresponding rows in the child table that reference it
click to copy
What is the difference between ALTER TABLE MODIFY and ALTER TABLE CHANGE in MySQL?
MODIFY changes a column definition (data type, constraints) but keeps the column name; CHANGE can rename the column AND change its definition (requires specifying the new column definition even if unchanged)
click to copy
What is the purpose of CREATE TABLE AS SELECT (CTAS) and what is NOT copied?
Creates a new physical table populated with data from the SELECT query results - but does NOT copy constraints (primary keys, foreign keys, indexes, check constraints) from the source
click to copy
What is a SQL DOMAIN concept and how does it differ from a simple column data type?
A domain is a named reusable column specification that combines a data type with optional constraints (DEFAULT, CHECK) allowing the domain to be used across multiple tables for consistency - defined with CREATE DOMAIN in standard SQL
click to copy
What is the purpose of the DEFERRABLE INITIALLY DEFERRED constraint option in SQL?
Constraints are checked at the end of a transaction (COMMIT) rather than after each statement allowing intermediate states to violate the constraint during a transaction
click to copy