Do I need to define clustered index on the primary key of a table explicity?> Do I need to define clustered index on the primary key of a table
> explicity?
A primary key constraint always creates a unique index so there is no need
to define one explicitly. You have the choice of creating the primary key
index as either clustered or non-clustered when you create the constraint.
If neither CLUSTERED nor NONCLUSTERED is specified and no clustered index
exists on the table, the default is clustered. A non-clustered primary key
index will be created if a clustered index already exists. Examples below:
ALTER TABLE dbo.MyTable
ADD CONSTRAINT PK_MyTable
PRIMARY KEY CLUSTERED (MyColumn)
ALTER TABLE dbo.MyTable
ADD CONSTRAINT PK_MyTable
PRIMARY KEY NONCLUSTERED (MyColumn)
--clustered if no existing clustered index, otherwise non-clustered
ALTER TABLE dbo.MyTable
ADD CONSTRAINT PK_MyTable
PRIMARY KEY (MyColumn)
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Man T" <alan_nospam_pltse@.yahoo.com.au> wrote in message
news:uOSlnYUoIHA.2064@.TK2MSFTNGP05.phx.gbl...
> Do I need to define clustered index on the primary key of a table
> explicity?
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment