Entity and Referential Integrity

Once you specify the primary key for each table, no further action is needed by client application developers or the database administrator to maintain entity integrity.

The table owner defines the primary key for a table when creating it. If the structure of a table is later modified, the primary key can also be redefined using the ALTER TABLE statement clauses DELETE PRIMARY KEY or ADD PRIMARY KEY. See Reference: Statements and Options.

Some application development systems and database design tools allow you to create and alter database tables. If you are using such a system, you may not have to explicitly enter the CREATE TABLE or ALTER TABLE command. The application generates the statement from the information you provide.

When you insert or update a table row, the database server ensures that the primary key for the table is still valid: that each row in the table is uniquely identified by the primary key.

Example 1

The Employees table in the demo database uses an employee ID as the primary key. When a new employee is added to the table, IQ checks that the new employee ID value is unique, and is not NULL. See Table Names and Owners in Introduction to SAP Sybase IQ for a list of tables in the demo database.

Example 2

The SalesOrderItems table in the demo database uses two columns to define a primary key.

This table holds information about the items that can be ordered. One column contains an id that specifies an order, but there may be several items on each order, so this column by itself cannot be a primary key. An additional line_id column identifies the line that corresponds to the item. Together, the columns id and line_id specify an item uniquely, and form the primary key. This is known as a multicolumn primary key.