programming beginner 10 sample questions

Indexes MCQ Practice Test

Data structures that speed up data retrieval operations on a database table.

Q1. Which of the following is a characteristic of a clustered index in a database?

Explanation: A clustered index in a database stores the data in a sorted order, which can improve query performance. This is in contrast to a non-clustered index, which only stores key values and not the actual data.

Q2. Which index type is most suitable for simple equality lookups (WHERE x = value) in databases that support it?

Explanation: Hash indexes excel at exact-match equality lookups (though not range queries); the original stem's 'mixed integer and string column' premise was malformed SQL.

Q3. What is the primary purpose of a clustered index in a database?

Explanation: A clustered index is a type of index that rearranges the physical order of the data in a table based on the index key. This can speed up data retrieval by allowing the database to quickly locate specific data based on the index key.

Q4. In a database with a large table containing a column of employee IDs and a column of corresponding salaries, which of the following index types would most likely improve query performance when executing a query that filters employees by a specific salary range?

Explanation: A non-clustered index on the salary column with an included employee ID column would allow the database to quickly locate the rows that match the salary range and then retrieve the corresponding employee IDs from the included column, improving query performance.

Q5. What is the primary benefit of creating a clustered index on a column used in the WHERE clause of a frequently executed query?

Explanation: A clustered index reorders the physical storage of data to match the index keys, allowing for faster query performance when the index is used in the WHERE clause.

Q6. A database index is created on a column with a high cardinality, but the column contains a large number of null values. Which of the following is a potential issue with this index?

Explanation: When a column with a high cardinality contains a large number of null values, the index may lead to a decrease in query performance. This is because the database needs to spend more time handling the null values, which can slow down the query execution time.

Q7. In a relational database, what is the primary difference between a clustered index and a non-clustered index on a table with a large number of rows?

Explanation: A clustered index rearranges the physical order of the rows in the table, whereas a non-clustered index does not. This is the primary difference between the two types of indexes, and it has significant implications for query performance and data retrieval.

Q8. A database has two indexes, one on the "name" column and another on the "age" column. Which of the following queries would benefit most from the use of an index on the "age" column?

Explanation: The query would benefit most from the use of an index on the "age" column because the index is created on the "age" column, and the query is filtering on the "age" column. This allows the database to quickly locate the relevant rows by scanning the index, rather than scanning the entire table.

Q9. Which of the following index types is best suited for a column that frequently participates in WHERE and JOIN clauses, and contains a large number of unique values?

Explanation: A non-clustered index with included columns is ideal for columns that participate in WHERE and JOIN clauses and contain a large number of unique values, as it allows for efficient lookups and minimizes the impact on the underlying table.

Q10. In a database with a composite index on columns A and B, which of the following queries will benefit from the index?

Explanation: A composite index on columns A and B can be used to efficiently retrieve data when both columns are specified in the WHERE clause, as in the query SELECT * FROM table WHERE A = 5 AND B = 10. This is because the index can be used to quickly locate the relevant data, reducing the number of rows that need to be scanned.

That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.

Sign Up Free
Indexes MCQ Practice Test | Mind Hustle