April 29th, 2009

How do Constraints Work?, PRIMARY KEY (Part 2 of 3)

Posted by admin in P. Table Creation

A primary key has the following features:

> One and only one primary key must be specified. It uses the reserved words PRIMARY KEY in the CREATE TABLE statement.

> A simple key (one column) can be defined as a column constraint or a table constraint. As a simple key column constraint, PRIMARY KEY is placed in the column definition.

> A composite key (multiple columns) can only be defines as a table constraint. As a table constraint, the PRIMARY KEY definition has the column names specified.

> The primary key columns can have NOT NULL specified on the column. If NOT NULL is not specified on primary key columns, most RDBMS systems set the columns to NOT NULL by default.
DB2 requires that NOT NULL be specified for primary key columns.

> Primary key values can not be changed. If you want to change the value of a primary key, you must DELETE the row and then INSERT the same row with new key values.

Comments are closed.

Sorry, the comment form is closed at this time.