0
0
SQLquery~20 mins

Single column index in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Single Column Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Single Column Index on Query Performance

Consider a table Employees with columns id, name, and department. A single column index is created on the department column.

What will be the output of the following query?

SELECT name FROM Employees WHERE department = 'Sales';

Assume the table has these rows:

id | name   | department
1  | Alice  | Sales
2  | Bob    | HR
3  | Carol  | Sales
4  | Dave   | IT
SQL
SELECT name FROM Employees WHERE department = 'Sales';
A["Alice", "Carol"]
B["Alice", "Bob", "Carol", "Dave"]
C[]
D["Bob", "Dave"]
Attempts:
2 left
💡 Hint

Think about which rows match the condition department = 'Sales'.

🧠 Conceptual
intermediate
1:30remaining
Purpose of Single Column Index

What is the main purpose of creating a single column index on a database table?

ATo automatically backup the table data
BTo speed up queries filtering or sorting by that column
CTo prevent any data from being inserted into that column
DTo store duplicate values in the column
Attempts:
2 left
💡 Hint

Think about how indexes help when searching data.

📝 Syntax
advanced
1:30remaining
Correct Syntax to Create Single Column Index

Which SQL statement correctly creates a single column index named idx_department on the department column of the Employees table?

AINDEX CREATE idx_department ON Employees(department);
BCREATE INDEX ON Employees idx_department(department);
CCREATE Employees INDEX idx_department ON department;
DCREATE INDEX idx_department ON Employees(department);
Attempts:
2 left
💡 Hint

Remember the order: CREATE INDEX index_name ON table(column);

optimization
advanced
2:00remaining
Query Optimization Using Single Column Index

Given a large Orders table with millions of rows, which query will benefit most from a single column index on the customer_id column?

ASELECT * FROM Orders WHERE customer_id = 12345;
BSELECT * FROM Orders WHERE order_date = '2023-01-01';
CSELECT COUNT(*) FROM Orders;
DSELECT * FROM Orders ORDER BY order_date;
Attempts:
2 left
💡 Hint

Indexes help when filtering by the indexed column.

🔧 Debug
expert
2:30remaining
Why Does This Query Not Use the Single Column Index?

Consider a single column index on department in the Employees table. Why does this query not use the index?

SELECT * FROM Employees WHERE UPPER(department) = 'SALES';
ABecause the query is missing a JOIN clause
BBecause the index only works with numeric columns
CBecause the function <code>UPPER()</code> on the column prevents index usage
DBecause the table has no rows
Attempts:
2 left
💡 Hint

Think about how functions on indexed columns affect index use.