Reports information about a primary, foreign, or common key of a particular table or view, or about all keys in the current database.


sp_helpkey [tabname]




There are additional considerations when using sp_helpkey:
  • sp_helpkey lists information about all primary, foreign, and common key definitions that reference the table tabname or, if tabname is omitted, about all the keys in the database. Define these keys with the sp_primarykey, sp_foreignkey, and sp_commonkey system procedures.

  • sp_helpkey does not provide information about the unique or primary key integrity constraints defined by a create table statement. Use sp_helpconstraint to determine what constraints are defined for a table.

  • Create keys to make explicit a logical relationship that is implicit in your database design so that applications can use the information.

  • If you specify an object name, sp_helpkey follows the SAP ASE rules for finding objects:
    • If you do not specify an owner name, and you own an object with the specified name, sp_helpkey reports on that object.

    • If you do not specify an owner name, and you do not own an object of that name, but the database owner does, sp_helpkey reports on the database owner’s object.

    • If neither you nor the database owner owns an object with the specified name, sp_helpkey reports an error condition, even if an object with that name exists in the database for a different owner.

    • If both you and the database owner own objects with the specified name, and you want to access the database owner’s object, specify the name in the form dbo.objectname.

  • Qualify objects that are owned by database users other than yourself and the database owner with the owner’s name, as in “mary.myproc”.

See also create trigger in Reference Manual: Commands.


Any user can execute sp_helpkey. Permission checks do not differ based on the granular permissions settings.


Values in event and extrainfo columns from the sysaudits table are:



Audit option


Command or access audited

Execution of a procedure

Information in extrainfo
  • Roles – Current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – All input parameters

  • Proxy information – Original login name, if set proxy in effect

Related reference