Creating primary and foreign keys – Sybase 12.4.2 User Manual
Page 145

CHAPTER 3 Working with Database Objects
125
Creating primary and foreign keys
The
CREATE TABLE
and
ALTER TABLE
statements allow many attributes of
tables to be set, including column constraints and checks. This section shows
how to set table attributes using the primary and foreign keys as an example.
Creating a primary
key
The following statement creates the same
skill
table as before, except that a
primary key is added:
CREATE TABLE skill (
skill_id INTEGER NOT NULL,
skill_name CHAR( 20 ) NOT NULL,
skill_type CHAR( 20 ) NOT NULL,
primary key( skill_id )
)
The primary key values must be unique for each row in the table which, in this
case, means that you cannot have more than one row with a given
skill_id
. Each
row in a table is uniquely identified by its primary key.
Columns in the primary key are not allowed to contain NULL. You must
specify
NOT NULL
on the column in the primary key.
Note
Adaptive Server IQ does not enforce multi-column primary keys. You
must specify the keyword
UNENFORCED
when you define a multi-column
primary key.
Creating a primary
key in Sybase Central
❖
To create a primary key in Sybase Central:
1
Connect to the database.
2
Click the Tables folder for that database.
3
Right-click the table you wish to modify, and select Properties from the
pop-up menu to display its property sheet.
4
Click the Columns tab, select the column name, and either click Add to
Key or Remove from Key.