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.

See also

Commands alter table, create table, create trigger

System procedures sp_commonkey, sp_dropkey, sp_foreignkey, sp_helpjoins, sp_helpkey