Solved

Find all my PK Indexes?

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

749 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