Solved

Find all my PK Indexes?

Posted on 2016-09-23
3
46 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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