tags:

views:

22

answers:

2

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
@TooFat - so there is not need to create index explicitly rite ?
pradeep
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
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
A: 

A Binary Tree Index should be created if you use a primary key.

http://dev.mysql.com/doc/refman/4.1/en/mysql-indexes.html

Kewley