0
0
SQLquery~10 mins

How an index works (B-tree mental model) in SQL - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a B-tree index on the column 'name' in the 'employees' table.

SQL
CREATE INDEX idx_name ON employees ([1]);
Drag options to blanks, or click blank then click option'
Aage
Bname
Csalary
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column that is not used in queries.
Using a column with many duplicate values which may not benefit much from indexing.
2fill in blank
medium

Complete the SQL query to use the index on 'name' to find employees named 'Alice'.

SQL
SELECT * FROM employees WHERE [1] = 'Alice';
Drag options to blanks, or click blank then click option'
Asalary
Bage
Cname
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering by a column that does not have an index.
Using a different column name in the WHERE clause.
3fill in blank
hard

Fix the error in the SQL query to use the index correctly for a range search on 'age'.

SQL
SELECT * FROM employees WHERE age [1] 30;
Drag options to blanks, or click blank then click option'
A>
BIN
CLIKE
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which only finds exact matches.
Using 'LIKE' which is for pattern matching, not numeric ranges.
4fill in blank
hard

Fill both blanks to create a B-tree index on 'department' and use it in a query filtering by 'department'.

SQL
CREATE INDEX idx_dept ON employees ([1]);
SELECT * FROM employees WHERE [2] = 'Sales';
Drag options to blanks, or click blank then click option'
Adepartment
Bname
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using different columns in the index and WHERE clause.
Using a column that is not indexed in the WHERE clause.
5fill in blank
hard

Fill all three blanks to create a B-tree index on 'salary', select employees with salary greater than 50000, and order results by salary.

SQL
CREATE INDEX idx_salary ON employees ([1]);
SELECT * FROM employees WHERE [2] [3] 50000 ORDER BY salary;
Drag options to blanks, or click blank then click option'
Asalary
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the WHERE clause.
Using different columns in the index and WHERE clause.