I'm often checking out what the primary keys are for tables that I'm working on. One of our free SDU Tools for developers and DBAs does just that. it's ListPrimaryKeyColumns.
You can see how to execute it in the main image above. The procedure takes these parameters:
@DatabaseName sysname – This is the database to process
@SchemasToList nvarchar(max) – a comma-delimited list of schemas to include (ie: 'Sales,Purchasing') or the word 'ALL'
@TablesToList nvarchar(max)- a comma-delimited list of tables to include (ie: 'Customers,Orders') or the word 'ALL'
One row is returned for each primary key.
The columns returned are SchemaName, TableName, PrimaryKeyName, NumberOfColumns, ColumnList.
You can see it in action here:
To become an SDU Insider and to get our free tools and eBooks, please just visit here:
Learn about indexing
Want to learn more about indexes? Take our online on-demand course now: https://training.sqldownunder.com/p/sql-server-indexing-for-developers