0
0
PostgreSQLquery~10 mins

Covering indexes with INCLUDE in PostgreSQL - Interactive Code Practice

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

Complete the code to create a basic index on the column 'last_name'.

PostgreSQL
CREATE INDEX idx_last_name ON employees([1]);
Drag options to blanks, or click blank then click option'
Alast_name
Bfirst_name
Cemployee_id
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a different column name than 'last_name'.
Forgetting to put the column name inside parentheses.
2fill in blank
medium

Complete the code to create an index on 'last_name' and include 'first_name' as an included column.

PostgreSQL
CREATE INDEX idx_last_name_include ON employees(last_name) INCLUDE ([1]);
Drag options to blanks, or click blank then click option'
Asalary
Bemployee_id
Cdepartment
Dfirst_name
Attempts:
3 left
💡 Hint
Common Mistakes
Including the wrong column instead of 'first_name'.
Omitting the parentheses around the included column.
3fill in blank
hard

Fix the error in the index creation by completing the INCLUDE clause with the correct column.

PostgreSQL
CREATE INDEX idx_salary_include ON employees(salary) INCLUDE ([1]);
Drag options to blanks, or click blank then click option'
Alast_name
Bsalary
Cemployee_id
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Including the same column as the indexed key column.
Choosing a column that does not help cover queries.
4fill in blank
hard

Fill both blanks to create an index on 'department' and include 'salary' and 'hire_date' columns.

PostgreSQL
CREATE INDEX idx_dept_include ON employees([1]) INCLUDE ([2]);
Drag options to blanks, or click blank then click option'
Adepartment
Bsalary, hire_date
Csalary
Dhire_date
Attempts:
3 left
💡 Hint
Common Mistakes
Putting multiple columns in the index key instead of INCLUDE.
Not separating included columns with commas.
5fill in blank
hard

Fill all three blanks to create an index on 'last_name' and include 'first_name' and 'email' columns.

PostgreSQL
CREATE INDEX idx_full_include ON employees([1]) INCLUDE ([2], [3]);
Drag options to blanks, or click blank then click option'
Alast_name
Bfirst_name
Cemail
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Including the indexed column in the INCLUDE clause.
Forgetting commas between included columns.