views:

135

answers:

4

Consider this unique constraint:

ALTER TABLE Posts
ADD CONSTRAINT UQ_Posts_Name
UNIQUE (Name);

Does it automatically create index on Name column?

+2  A: 

yes it does. See this

n8wrl
A: 

Yes, absolutely. A unique constraint creates a unique index.

Max
+1  A: 

You can create a separate index on it as well. this article http://msdn.microsoft.com/en-us/library/aa224827(SQL.80).aspx describes the differences very well.

AutomatedTester
+1  A: 

Yes, just to add.. creating primary key automatically creates clustered index.

EDIT: I was wrong... after Lieven's comment:

When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index. The primary key column cannot allow NULL values.

Svetlozar Angelov
Creating a primary key does **not** automatically creates a clustered index.
Lieven
you are right - When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index. The primary key column cannot allow NULL values.
Svetlozar Angelov