Defines a primary key on a table or view.
sp_primarykey tabname, col1 [, col2, col3, ..., col8]
sp_primarykey authors, au_id
sp_primarykey employees, lastname, firstname
Executing sp_primarykey adds the key to the syskeys table. Only the owner of a table or view can define its primary key. sp_primarykey does not enforce referential integrity constraints; use the primary key clause of the create table or alter table command to enforce a primary key relationship.
Define keys with sp_primarykey, sp_commonkey, and sp_foreignkey to make explicit a logical relationship that is implicit in your database design. An application program can use the information.
A table or view can have only one primary key. To display a report on the keys that have been defined, execute sp_helpkey.
The installation process runs sp_primarykey on the appropriate columns of the system tables.
See also alter table, create table, create trigger in Reference Manual: Commands.
You must be the table owner to execute sp_primarykey. Permission checks do not differ based on the granular permissions settings.
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|