Can you explain clustered and non-clustered indexes and how they are created?
💡 Model Answer
A clustered index determines the physical order of rows in a table. Because the data is stored in that order, a table can have only one clustered index, usually the primary key. A non‑clustered index is a separate structure that contains the indexed columns plus a pointer to the actual row. Multiple non‑clustered indexes can exist on a table.
To create a clustered index:
CREATE CLUSTERED INDEX IX_Table_Col ON dbo.TableName(ColName);To create a non‑clustered index:
CREATE NONCLUSTERED INDEX IX_Table_Col ON dbo.TableName(ColName);When you declare a primary key, SQL Server automatically creates a clustered index unless you specify otherwise. Non‑clustered indexes improve query performance for lookups, joins, and ordering, but they add storage overhead and can slow writes because the index must be updated.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500