sp_primarykey

Description

Defines a primary key on a table or view.

Syntax

sp_primarykey tabname, col1 [, col2, col3, ..., col8]

Parameters

tabname

is the name of the table or view on which to define the primary key.

col1

is the name of the first column that makes up the primary key. The primary key can consist of from one to eight columns.

Examples

Example 1

Defines the au_id field as the primary key of the table authors:

sp_primarykey authors, au_id

Example 2

Defines the combination of the fields lastname and firstname as the primary key of the table employees:

sp_primarykey employees, lastname, firstname

Usage

Permissions

Only the owner of the specified table or view can execute sp_primarykey.

Auditing

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

  • 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

See also

Commands alter table, create table, create trigger

System procedures sp_commonkey, sp_dropkey, sp_foreignkey, sp_helpjoins, sp_helpkey