Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know if primary key is CLUSTERED or NONCLUSTERED 1

Status
Not open for further replies.

popseven

Technical User
Apr 4, 2006
17
0
0
PH
Hi Guys,

Is there a way to know via query if a PRIMARY KEY on a particular mssql 2000 table was declared as NONCLUSTERED or CLUSTERED index?

TIA,
popseven
 
This may not be exactly what you are looking for, but....

sp_helpindex [!]TableName[/!]

This is what I get (for Index Description) for one of my tables...

[tt][blue]
index_description
-------------------------------------------------
clustered, unique, primary key located on PRIMARY
[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi,

actually, I need to change the index from NONCLUSTERED to CLUSTERED for a particular table but I need to check first (via script) before I change. If it's already CLUSTERED, I will skip it.

 
Take a look at this thread. thread183-1151951

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
This query will show you the primary keys that are NOT clustered.

Code:
Select  object_name(id) As TableName, 
        Name
From    sysindexes
Where   Status & 16 = [!]0[/!]
        And Status & 2048 = 2048

And the primary keys that are clustered...

Code:
Select  object_name(id) As TableName, 
        Name
From    sysindexes
Where   Status & 16 = [!]16[/!]
        And Status & 2048 = 2048

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top