hi, I create a column as primary key , does this create indexes automatically ? or do i need to create indexes explicitly. i was under assumption that primary key also maintains indexes
+2
A:
In SQL Server creating a Primary key will create a Unique Clustered Index on that Column. or more specifically from here
Note PRIMARY KEY constraints create clustered indexes automatically if no clustered index already exists on the table and a nonclustered index is not specified when you create the PRIMARY KEY constraint.
TooFat
2010-07-20 15:20:38
@TooFat - so there is not need to create index explicitly rite ?
pradeep
2010-07-20 15:25:26
If you don't already have a clustered index already specified on the table and you are not telling it to use a diff non-clustered index then the index and constraints will be automatically created for you. (As an FYI a clustered index physically sorts the order of the data so there can only ever be one clustered index per table)
TooFat
2010-07-20 15:50:47
Another note you mention indexes (plural). Creating the primary key creates a single clustered index it doesn't magically figure where indexes are needed and create them for you. You may find that you will need to add some non-clustered indexes to improve performance as well.
TooFat
2010-07-20 15:55:26