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.
Summary of Contents for Adaptive Server IQ 12.4.2
Page 1: ...Administration and Performance Guide Adaptive Server IQ 12 4 2 ...
Page 16: ...xvi ...
Page 20: ...Related documents xx ...
Page 40: ...Compatibility with earlier versions 20 ...
Page 118: ...Troubleshooting startup shutdown and connections 98 ...
Page 248: ...Importing data by replication 228 ...
Page 306: ...Integrity rules in the system tables 286 ...
Page 334: ...Cursors in transactions 314 ...
Page 396: ...Users and permissions in the system tables 376 ...
Page 438: ...Determining your data backup and recovery strategy 418 ...
Page 484: ...Network performance 464 ...
Page 500: ...System utilities to monitor CPU use 480 ...
Page 514: ...Characteristics of Open Client and jConnect connections 494 ...
Page 536: ...Index 516 ...