I recently had the following question posted to this site:
Hello,
I’d think this is a simple question/problem. I want to get the primary key name for each table in my schema. By doing so, it will make my search easier when looking at the database. I have schema X with many tables. I want to know the primary key to each table and return it in a report form. So, basically my question is, “Give me the column name of each primary key of each table in schema X.” Is there a simple SQL statement to do this?
Thank you.
The following query allows you to view all primary keys for all user tables in the current database. You can tweak it to return results for a given schema or any other set of parameters.
Please send me any questions you have about SQL Server and I’d be glad to answer them here.
Filed under: SQL Server 2005, SQL Server 2008, T-SQL Tagged: SQL Server
