Solved

Find all my PK Indexes?

Posted on 2016-09-23
3
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

617 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