0% found this document useful (0 votes)
15 views7 pages

SQL Indexing Quiz

The document is a quiz consisting of 25 questions related to SQL indexing, covering topics such as the purpose of indexes, types of indexes, and their advantages and disadvantages. Each question includes multiple-choice answers along with explanations for the correct answers. The quiz aims to test knowledge on SQL indexing concepts and practices.

Uploaded by

kyletheboss543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

SQL Indexing Quiz

The document is a quiz consisting of 25 questions related to SQL indexing, covering topics such as the purpose of indexes, types of indexes, and their advantages and disadvantages. Each question includes multiple-choice answers along with explanations for the correct answers. The quiz aims to test knowledge on SQL indexing concepts and practices.

Uploaded by

kyletheboss543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

✅ SQL Indexing Quiz: 25 Questions

1. What is the main purpose of an index in SQL?

A. To sort the table


B. To reduce storage space
C. To speed up data retrieval
D. To delete rows faster
Answer: C
Explanation: Indexes are used to speed up data retrieval operations on a
database table.

2. Which type of index is automatically created when you define a


primary key?

A. Bitmap index
B. Composite index
C. Unique index
D. Hash index
Answer: C
Explanation: A unique index is automatically created on a column defined
as a PRIMARY KEY to enforce uniqueness.

3. Which of the following is a drawback of using indexes?

A. Increases query speed


B. Reduces disk space
C. Increases the time for INSERT, UPDATE, DELETE
D. Increases data consistency
Answer: C
Explanation: Indexes slow down write operations because they must be
updated with the data.

4. What is a composite index?

A. An index on a computed column


B. An index on a primary key
C. An index on multiple columns
D. An index on a foreign key
Answer: C
Explanation: A composite index is created on two or more columns.

5. Which SQL command is used to create an index?

A. CREATE TABLE
B. CREATE INDEX
C. MAKE INDEX
D. INDEX CREATE
Answer: B
Explanation: CREATE INDEX is the standard SQL command to create an
index.

6. Which of the following types of indexes stores a map of key


values to row locations?

A. Hash index
B. Clustered index
C. Bitmap index
D. Spatial index
Answer: A
Explanation: A hash index uses a hash function to map keys to rows for fast
lookup.

7. How many clustered indexes can a table have?

A. Unlimited
B. One per column
C. One only
D. Two if there are foreign keys
Answer: C
Explanation: A table can have only one clustered index, as it defines the
physical order of the rows.

8. Which index type is best for columns with a small number of


distinct values (e.g., gender)?
A. Hash index
B. Bitmap index
C. B-tree index
D. Composite index
Answer: B
Explanation: Bitmap indexes are efficient for low-cardinality data.

9. What happens if you create an index on a column with many


NULLs?

A. Index is ignored
B. Index is automatically clustered
C. It may not be as efficient
D. SQL throws an error
Answer: C
Explanation: Indexing a column with many NULLs may reduce performance
benefits due to less selectivity.

10. What is a B-tree index best used for?

A. Columns with many duplicate values


B. Full-text search
C. Range and equality queries
D. Spatial queries
Answer: C
Explanation: B-tree indexes are optimal for range and equality queries.

11. When is it best to avoid indexing a column?

A. When the column is queried often


B. When the column is part of a WHERE clause
C. When the column has high cardinality
D. When the column is updated frequently
Answer: D
Explanation: Frequent updates can degrade performance if the column is
indexed.
12. Which of these commands removes an index?

A. DROP INDEX
B. DELETE INDEX
C. REMOVE INDEX
D. ERASE INDEX
Answer: A
Explanation: DROP INDEX removes an existing index.

13. What type of index does SQL Server create by default?

A. B-tree
B. Bitmap
C. Hash
D. Clustered
Answer: A
Explanation: SQL Server uses B-tree-based indexing structures.

14. Which index type physically reorders the table rows?

A. Non-clustered
B. Clustered
C. Unique
D. Bitmap
Answer: B
Explanation: A clustered index determines the physical order of data in the
table.

15. Can non-unique indexes contain duplicate values?

A. No
B. Yes
C. Only on primary keys
D. Only on foreign keys
Answer: B
Explanation: Non-unique indexes can have duplicates, unlike unique
indexes.
16. What is a covering index?

A. Index with a hash function


B. Index that includes all columns used in a query
C. Index on a computed column
D. Index with no NULLs
Answer: B
Explanation: A covering index includes all columns needed by a query,
reducing need to access the base table.

17. Which clause would help in creating an index on a view in SQL


Server?

A. WITH VIEW
B. CREATE INDEX ON VIEW
C. SCHEMABINDING
D. INDEXABLE
Answer: C
Explanation: SCHEMABINDING is required to create indexed views in SQL
Server.

18. What does a partial index do?

A. Indexes only a part of a column


B. Indexes only rows that meet a condition
C. Indexes only the first few rows
D. Indexes only foreign keys
Answer: B
Explanation: Partial indexes include only rows that satisfy a WHERE clause
condition.

19. In PostgreSQL, what is a GIN index used for?

A. Geospatial data
B. Range queries
C. Full-text search
D. Binary data
Answer: C
Explanation: GIN (Generalized Inverted Index) is used for full-text search
and array indexing in PostgreSQL.

20. Can you create an index on a view?

A. No
B. Yes, if the view is materialized
C. Only on subqueries
D. Only on temporary views
Answer: B
Explanation: Indexed (materialized) views can have indexes.

21. Which function improves query performance by suggesting


missing indexes in SQL Server?

A. sys.indexes
B. Query Store
C. Database Engine Tuning Advisor
D. sys.dm_exec_sessions
Answer: C
Explanation: The Database Engine Tuning Advisor can suggest beneficial
indexes.

22. Why might too many indexes hurt performance?

A. Increases SELECT time


B. Increases storage size and slows down INSERT/UPDATE/DELETE
C. Prevents query compilation
D. Increases transaction locking
Answer: B
Explanation: Maintaining many indexes increases overhead during write
operations.

23. What happens if two indexes cover the same query?

A. SQL errors out


B. SQL picks both
C. SQL optimizer chooses the most efficient one
D. SQL ignores the indexes
Answer: C
Explanation: The query optimizer evaluates cost and chooses the best
index.

24. How can you see the indexes on a table in MySQL?

A. SHOW INDEXES FROM table_name;


B. SELECT * FROM INDEXES;
C. LIST INDEX table_name;
D. SHOW TABLE INDEX table_name;
Answer: A
Explanation: The correct MySQL syntax is SHOW INDEXES FROM
table_name;.

25. What is the benefit of indexing foreign keys?

A. Prevents table locks


B. Ensures data integrity
C. Improves JOIN performance
D. Reduces storage
Answer: C
Explanation: Indexing foreign keys improves performance of JOIN
operations.

You might also like