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]
is the name of a table or view in the current database. If you do not specify a name, the procedure reports on all keys defined in the current database.
Displays information about the keys defined in the current database. The “object_keys” and “related_keys” columns refer to the names of the columns that make up the key:
sp_helpkey
keytype object related_object object_keys related_keys ------- ------- -------------- --------------- -------------- primary authors -- none -- au_id,*,*,*,*,*,*,* *,*,*,*,*,*,*,* foreign titleauthor authors au_id,*,*,*,*,*,*,* au_id,*,*,*,*,*, *,*
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 Adaptive Server 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”.
Any user can execute sp_helpkey.
Values in event and extrainfo columns from the sysaudits table are:
Event |
Audit option |
Command or access audited |
Information in extrainfo |
---|---|---|---|
38 |
exec_procedure |
Execution of a procedure |
|
Commands create trigger
System procedures sp_commonkey, sp_foreignkey, sp_primarykey