SQL Interview Questions 1725044566
SQL Interview Questions 1725044566
DELETE TRUNCATE
Removes specific rows based on a condition. Removes all rows from the table.
Can be rolled back if used within a
Cannot be rolled back once executed.
transaction.
Slower as it logs individual row deletions. Faster as it does not log individual deletions.
Activates triggers if present. Does not activate triggers.
Leaves table structure and indexes intact. Resets table structure and reclaims space.
WHERE HAVING
Filters rows before grouping or aggregation. Filters groups after aggregation.
Used with SELECT, UPDATE, and DELETE
Used only with SELECT statements.
statements.
Cannot use aggregate functions (e.g., SUM,
Can use aggregate functions.
COUNT).
Filters groups of rows based on aggregate
Filters individual rows based on conditions.
conditions.
Applied before any grouping is done in a
Applied after the GROUP BY clause in a query.
query.
RANK DENSE_RANK
Assigns a unique rank to each row within a
Similar to RANK but without gaps in ranking.
partition of a result set.
Skips ranks when there are ties (e.g., 1, 2, 2, Does not skip ranks; consecutive ranks (e.g., 1,
4). 2, 2, 3).
Introduces gaps if there are ties in the
No gaps; ranks increase consecutively.
ranking.
Syntax: RANK() OVER (PARTITION BY ... Syntax: DENSE_RANK() OVER (PARTITION
ORDER BY ...). BY ... ORDER BY ...).
Ideal when gaps in rank numbers are Ideal when continuous ranking without gaps is
acceptable. needed.
OLTP OLAP
Designed for managing transactional data. Designed for analytical and reporting purposes.
Handles a large number of short online Handles complex queries involving data
transactions (e.g., INSERT, UPDATE, DELETE). aggregation and analysis.
Data is often denormalized to optimize query
Data is highly normalized to reduce redundancy.
performance.
Focuses on speed and efficiency for daily Focuses on query performance and data
operations. retrieval speed for analysis.
Typical operations include order entry, Typical operations include data mining,
payments, and customer management. forecasting, and business reporting.
Databases are typically large, integrating data
Databases are typically smaller in size.
from multiple sources.
Examples: Banking systems, e-commerce Examples: Data warehouses, business
websites. intelligence systems.