Returns primary key information for a single table in the current environment.
Name of the table qualifier. This field can be NULL.
Name of the table owner. This field always returns a value.
Name of the table. In SQL Server, this column represents the table name as listed in the sysobjects table. This field always returns a value.
Name of the column, for each column of the TABLE_NAME returned. In SQL Server, this column represents the column name as listed in the sys.columns table. This field always returns a value.
Sequence number of the column in a multicolumn primary key.
Primary key identifier. Returns NULL if not applicable to the data source.
sp_pkeys returns information about columns explicitly defined with a PRIMARY KEY constraint. Because not all systems support explicitly named primary keys, the gateway implementer determines what constitutes a primary key. Note that the term primary key refers to a logical primary key for a table. It is expected that every key listed as being a logical primary key has a unique index defined on it. This unique index is also returned in sp_statistics.
The sp_pkeys stored procedure is equivalent to SQLPrimaryKeys in ODBC. The results returned are ordered by TABLE_QUALIFIER, TABLE_OWNER, TABLE_NAME, and KEY_SEQ.
The following example retrieves the primary key for the HumanResources.Department table in the AdventureWorks2008R2 database.
USE AdventureWorks2008R2; GO EXEC sp_pkeys @table_name = N'Department' ,@table_owner = N'HumanResources';