Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ () — Sybase SQL Server 4.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

  1                       Version 4.0 -- 1/15/89           sp_primarykey
  ______________________________________________________________________

  NAME:  sp_primarykey

  FUNCTION:
       Defines a primary key on a table or view.

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

  EXAMPLES:
       1)  sp_primarykey authors, au_id

           The primary key of authors is the au_id field.







  sp_primarykey           Version 4.0 -- 1/15/89                       2
  ______________________________________________________________________
       2)  sp_primarykey employees, lastname, firstname

           The primary key of a table named employees is the combination
           of the fields lastname and firstname.

  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 between one and eight
           columns.

  COMMENTS:

       o Executing sp_primarykey adds the key to the syskeys table.
       o Keys are created in order to make explicit a logical  relation-
         ship that is implicit in your database design.  The information



  3                       Version 4.0 -- 1/15/89           sp_primarykey
  ______________________________________________________________________
         can be used by an application program.

       o To display a report on the keys that have been defined, execute
         sp_helpkey.
       o Only the owner of a table or view can define its primary key.

       o A table or view can have only one primary key.
       o SQL Server installation scripts installmaster and  installmodel
         execute the sp_primarykey procedure on all system tables.

  MESSAGES:
       The table or view supplied as the tabname parameter doesn't exist
           in the current database.
       You aren't the owner of the table or view  and  therefore  cannot
           define its primary key.
       A table or view can have only have one primary key;  one  already
           exists   on  the  table  or  view  supplied  as  the  tabname



  sp_primarykey           Version 4.0 -- 1/15/89                       4
  ______________________________________________________________________
           parameter.
       The column name supplied as one  of  the  column  names  isn't  a
           column in tabname.
       The primary key has been added to the syskeys table.

  PERMISSIONS:
       Execute permission to tabname owner.

  TABLES USED:
       syscolumns, syskeys, sysobjects

  SEE ALSO:
       sp_commonkey,    sp_helpjoins,     sp_dropkey,     sp_foreignkey,
       sp_helpkey, CREATE TRIGGER





Typewritten Software • bear@typewritten.org • Edmonds, WA 98026