wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

SQL CTE Quiz

Total questions: 15

Worksheet time: 3mins

Name
Class
Date
1.

What does a CTE (Common Table Expression) do?

a)

Stores data permanently

b)

Creates indexes

c)

Defines a temporary result set used by a query

d)

Updates a view

2.

What keyword is used to start a CTE?

a)

BEGIN

b)

CTE

c)

WITH

d)

DECLARE

3.

Which of the following is true about CTEs?

a)

They must always be recursive

b)

Can be referenced multiple times in the same query

c)

Stored in the database schema

d)

Always require a JOIN

4.

What distinguishes a Recursive CTE from a Non-Recursive CTE?

a)

It uses indexes

b)

It references itself

c)

It uses views

d)

It returns NULLs

5.

What must a Recursive CTE include?

a)

Aggregates

b)

A LIMIT clause

c)

An anchor (base) query and a recursive query

d)

A materialized view

6.

What keyword combines the anchor and recursive parts of a CTE?

a)

UNION

b)

JOIN

c)

UNION ALL

d)

INTERSECT

7.

Which of the following is a valid use case for recursive CTEs?

a)

Flattening JSON

b)

Building hierarchical data

c)

String matching

d)

Materialized joins

8.

What happens if a Recursive CTE does not have a stopping condition?

a)

Query is faster

b)

It runs infinitely or throws an error

c)

It self-corrects

d)

It returns zero rows

9.

What is a limitation of CTEs?

a)

Can’t reference tables

b)

Can’t include aggregates

c)

Can’t be indexed

d)

Must be permanent

10.

Which of the following can be used in a non-recursive CTE?

a)

Joins

b)

Aggregations

c)

Filters

d)

All of the above

11.

Can you use multiple CTEs in a single query?

a)

No

b)

Yes, but only one level

c)

Yes, comma-separated

d)

Only in views

12.

What does the following syntax define? WITH RegionalSales AS (SELECT Region, SUM(Sales) AS TotalSales FROM Orders GROUP BY Region) SELECT * FROM RegionalSales;

a)

Recursive CTE

b)

Non-recursive CTE

c)

Temporary table

d)

Materialized view

13.

What is a benefit of using CTEs over subqueries?

a)

Easier to debug and read

b)

Can replace views

c)

Persist across sessions

d)

CTEs are always faster

14.

What is the purpose of the anchor part in a recursive CTE?

a)

Defines the recursion limit

b)

Defines the starting rows

c)

Deletes base data

d)

Returns NULL

15.

When would you not use a recursive CTE?

a)

To find hierarchy depth

b)

To flatten a tree

c)

To calculate aggregates per region

d)

To expand manager-subordinate chains