Solved

Find all my PK Indexes?

Posted on 2016-09-23
3
41 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:
ScottPletcher 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now