Quantcast
Viewing all articles
Browse latest Browse all 32

SQL SERVER – Listing Primary Key of Table with Stored Procedure sp_pkeys

Here is a follow up blog post of my earlier blog post on very similar subject Listing Foreign Key Relationships of Table with Stored Procedure sp_fkeys. In previous blog post we listed foreign keys and now we will list the primary key of the table with the help of Stored Procedure sp_fkeys.

Here is a quick script how you can use stored procedure sp_pkeys to list the primary key. This stored procedure takes a minimum of two parameters a) name of the table, b) name of the schema.

USE AdventureWorks2012;
GO
EXEC sp_pkeys @table_name = N'Employee',
@table_owner = N'HumanResources';

Here is the output generated from the script listed above:

Image may be NSFW.
Clik here to view.

Here is an alternate way to list the keys as well - Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database.

Reference: Pinal Dave (http://blog.sqlauthority.com)


Filed under: PostADay, SQL, SQL Authority, SQL Constraint and Keys, SQL Query, SQL Server, SQL Tips and Tricks, T SQL Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 32

Trending Articles