Creating Primary Keys

Each row in a table is uniquely identified by its primary key.

The CREATE TABLE and ALTER TABLE statements allow many attributes of tables to be set, including column constraints and checks.

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.

Columns in the primary key are not allowed to contain NULL. You must specify NOT NULL on the column in the primary key.

Related tasks
Connecting to the Demo Database from Sybase Central
Connecting to the Demo Database from Interactive SQL
Creating Foreign Keys