Solved

Find all my PK Indexes?

Posted on 2016-09-23
3
44 Views
Last Modified: 2016-09-27
SQL Server.
How can I get a list of all my PK Indexes and whether they are clustered or non clustered?
0
Comment
Question by:Jess31
3 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 41812875
SELECT name, type_desc
FROM sys.indexes
WHERE is_primary_key = 1
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 41813021
SELECT
    OBJECT_NAME(i.object_id) AS table_name,
    i.name AS index_name,
    CASE WHEN i.type = 1 THEN 'Yes' ELSE 'No' END AS is_clustered,
    (SELECT COUNT(*) FROM sys.index_columns ic
     WHERE ic.object_id = i.object_id AND ic.index_id = i.index_id) AS total_columns
FROM sys.indexes i
WHERE i.is_primary_key = 1
ORDER BY table_name
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question