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 → Introduction to DBMS 29

ROW_NUMBER() vs RANK(): key difference
ROW_NUMBER gives unique numbers even for ties; RANK skips numbers after ties
click to copy
DENSE_RANK() vs RANK(): key difference
RANK skips numbers after ties; DENSE_RANK does NOT skip
click to copy
PERCENT_RANK() of lowest-ranked row (rank N of N total) is
1.0
click to copy
CUME_DIST() of top row is
1.0/N
click to copy
Window function can appear in which SQL clause
SELECT and ORDER BY only
click to copy
INTERSECT returns rows common to
BOTH result sets
click to copy
EXCEPT (MINUS) returns
Rows in FIRST result NOT in second
click to copy
A correlated subquery references
Columns from the outer query and executes once per outer row
click to copy
A derived table is a subquery in
FROM clause
click to copy
EXISTS vs IN: which is preferred for large subquery results
EXISTS is often better for large subquery results (stops at first match)
click to copy
ALL operator: salary > ALL(subquery) means salary is
Greater than EVERY value in subquery (greater than MAX)
click to copy
ANY/SOME operator: salary > ANY(subquery) means salary is
Greater than AT LEAST ONE value in subquery (greater than MIN)
click to copy
Recursive CTE ANCHOR member is
The base case (initial result set)
click to copy
COALESCE vs ISNULL: key difference
ISNULL takes only 2 arguments; COALESCE takes multiple arguments
click to copy
CASE WHEN grade>=90 THEN 'A' WHEN grade>=80 THEN 'B' ELSE 'C' END assigns
Grade categories using IF-THEN-ELSE logic
click to copy
PIVOT operation converts
Rows into columns (rotates table)
click to copy
CTE advantages over subqueries include
Improved readability and can be referenced multiple times in same query
click to copy
Which prevents SQL injection in parameterized queries
Using ? or named parameters so user input treated as data not SQL code
click to copy
GRANT SELECT,INSERT ON questions TO user1 grants
SELECT and INSERT privileges on questions table to user1
click to copy
REVOKE ALL PRIVILEGES ON questions FROM user1
Removes all privileges on questions table from user1
click to copy
IDENTITY/AUTO_INCREMENT column value
Is automatically generated as next sequential integer
click to copy
Which SQL returns only the top 5 highest paid employees
SELECT * FROM emp ORDER BY salary DESC LIMIT 5
click to copy
Which SQL data type is best for storing money/currency values
DECIMAL(15,2)
click to copy
VARCHAR vs CHAR: VARCHAR stores
Variable-length strings using only needed space
click to copy
TEXT vs VARCHAR: TEXT stores
Large text (up to 65,535 chars) without specifying max length
click to copy
DATETIME vs TIMESTAMP in MySQL
TIMESTAMP converts to UTC; DATETIME stores as-is
click to copy
Which SQL command creates a backup of table structure only
CREATE TABLE backup LIKE source
click to copy
Index on column with 1 million rows and 2 distinct values (gender) is
Useless since selectivity is extremely low (50% match) - optimizer may skip it
click to copy
Covering index for SELECT id,name FROM emp WHERE dept='IT' should include
dept, id, name columns
click to copy

DBMS → SQL Basics 4

FIRST_VALUE(salary) OVER(PARTITION BY dept ORDER BY hire_date) returns
First hire's salary in each department
click to copy
LAST_VALUE(salary) OVER(PARTITION BY dept ORDER BY hire_date ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) returns
Last hire's salary in each department
click to copy
Which SQL aggregates strings across rows
GROUP_CONCAT() or STRING_AGG()
click to copy
Which SQL creates a view that prevents DML violating its WHERE clause
CREATE VIEW v AS SELECT...WITH CHECK OPTION
click to copy

DBMS → Transactions 2

BEGIN TRANSACTION / START TRANSACTION
Explicitly starts a new transaction
click to copy
SAVEPOINT sp1 followed by ROLLBACK TO sp1
Undoes ONLY work done AFTER savepoint sp1 was created
click to copy

DBMS → Relational Model 1

ON DELETE SET NULL foreign key option
Sets child FK column to NULL when parent row is deleted
click to copy

DBMS → Views 1

Updatable view conditions: a view is NOT updatable when it contains
DISTINCT, GROUP BY, aggregate functions, UNION, or joins to multiple tables
click to copy

DBMS → PL/SQL 3

BEFORE trigger can be used to
Validate or modify NEW values before they are saved to the database
click to copy
AFTER trigger is best for
Audit logging - recording what changed after the operation succeeded
click to copy
Stored procedure IN OUT parameter difference
IN: pass value to procedure. OUT: return value from procedure. INOUT: both
click to copy