sp_primarykeys (Transact-SQL)
Returns the primary key columns, one row per key column, for the specified remote table.
|
Column name |
Data type |
Description |
|---|---|---|
|
TABLE_CAT |
sysname |
Table catalog. |
|
TABLE_SCHEM |
sysname |
Table schema. |
|
TABLE_NAME |
sysname |
Name of the table. |
|
COLUMN_NAME |
sysname |
Name of the column. |
|
KEY_SEQ |
int |
Sequence number of the column in a multicolumn primary key. |
|
PK_NAME |
sysname |
Primary key identifier. Returns NULL if not applicable to the data source. |
sp_primarykeys is executed by querying the PRIMARY_KEYS rowset of the IDBSchemaRowset interface of the OLE DB provider corresponding to table_server. The table_name, table_schema, table_catalog, and column parameters are passed to this interface to restrict the rows returned.
sp_primarykeys returns an empty result set if the OLE DB provider of the specified linked server does not support the PRIMARY_KEYS rowset of the IDBSchemaRowset interface.
The following example returns primary key columns from the LONDON1 server for the HumanResources.JobCandidate table in the AdventureWorks2012 database.
EXEC sp_primarykeys @table_server = N'LONDON1', @table_name = N'JobCandidate', @table_catalog = N'AdventureWorks2012', @table_schema = N'HumanResources';
