Difficulty: Easy
Correct Answer: primary keys only.
Explanation:
Introduction / Context:
Indexes often accompany constraints in SQL Server to enforce uniqueness and performance. Understanding which constraints auto-create indexes helps with design and troubleshooting.
Given Data / Assumptions:
Concept / Approach:
Creating a PRIMARY KEY constraint automatically creates a unique index on the key columns (clustered by default if the table does not already have a clustered index). FOREIGN KEY constraints do not automatically create an index, though adding one is typically recommended for referential integrity checks and join performance.
Step-by-Step Solution:
Verification / Alternative check:
Script out a table with a primary key; SQL Server shows a corresponding unique index. Adding a foreign key does not show a new index unless explicitly created.
Why Other Options Are Wrong:
Foreign key only: false. Both primary and foreign keys: overstates behavior. Never automatically: contradicts primary key behavior.
Common Pitfalls:
Forgetting to index foreign keys, which can slow deletes/updates on the referenced table and joins. Assuming the primary key must be clustered—this is configurable.
Final Answer:
primary keys only.
Discussion & Comments