Advanced SQL Concepts Flashcards

(30 cards)

1
Q

What is a Common Table Expression (CTE) in SQL?

A

A CTE is like creating a temporary named result set inside a query so the query becomes easier to read and reuse. Instead of writing a long complicated subquery multiple times you give it a name with WITH and then reference it like a temporary table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What problem do CTEs solve?

A

They break complex queries into smaller understandable steps. Think of them like intermediate calculations in math where you store a result before continuing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Window Function?

A

A window function lets you perform calculations across related rows without collapsing them into one row like GROUP BY does. It lets every row see its neighbors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the OVER() clause used for?

A

OVER tells SQL what group of rows a window function should look at. You define the “window” of rows the calculation should consider.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does ROW_NUMBER() do?

A

ROW_NUMBER assigns a unique sequential number to rows within a group. Imagine numbering students in each classroom starting from 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does RANK() do?

A

RANK orders rows but allows ties. If two rows tie for first place they both get rank 1 and the next rank becomes 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does DENSE_RANK() do?

A

DENSE_RANK is similar to RANK but it does not skip numbers when there are ties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does PARTITION BY do?

A

PARTITION BY splits rows into groups for window functions. It is like running the same calculation separately for each category.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Subquery?

A

A subquery is a query inside another query. It is used when you need a result first before finishing the main query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Correlated Subquery?

A

A correlated subquery depends on the outer query. For every row of the outer query the inner query runs again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Index in SQL?

A

An index is like a book index. Instead of scanning the whole table the database jumps directly to where the data lives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why do indexes improve performance?

A

Without an index the database must scan every row. With an index it uses a sorted structure to find data quickly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Composite Index?

A

A composite index indexes multiple columns together. It helps when queries filter using multiple columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Query Optimization?

A

Query optimization is the process the database uses to find the fastest way to run your query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an Execution Plan?

A

An execution plan is the database’s step-by-step strategy for how it will retrieve the requested data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Normalization?

A

Normalization organizes tables so that each piece of information is stored once. This prevents duplication and keeps data consistent.

17
Q

What is Denormalization?

A

Denormalization intentionally duplicates data to make queries faster at the cost of extra storage.

18
Q

What is a Primary Key?

A

A primary key uniquely identifies each row in a table. No two rows can share the same primary key.

19
Q

What is a Foreign Key?

A

A foreign key links one table to another by referencing its primary key.

20
Q

What is a Materialized View?

A

A materialized view stores the result of a query physically so the database does not need to recompute it every time.

21
Q

What is an Aggregate Function?

A

An aggregate function summarizes many rows into a single value like totals or averages.

22
Q

What are examples of aggregate functions?

23
Q

What is a Stored Procedure?

A

A stored procedure is a reusable program stored inside the database that can run complex logic.

24
Q

What is a Trigger?

A

A trigger is automatic code that runs when certain events happen in the database such as INSERT or UPDATE.

25
What is ETL in data engineering?
ETL stands for Extract Transform Load. Data is pulled from sources transformed into the correct structure and then loaded into a database or warehouse.
26
What is a Data Warehouse?
A data warehouse is a system designed specifically for analyzing large volumes of data rather than handling transactions.
27
What is OLTP?
OLTP systems handle day-to-day transactions like inserting orders or updating accounts.
28
What is OLAP?
OLAP systems focus on analyzing large datasets and running complex queries for insights.
29
What is Data Partitioning?
Partitioning splits a large table into smaller pieces so queries can run faster by scanning less data.
30
What is Sharding?
Sharding spreads a database across multiple servers so the workload is distributed.