Database Reference
In-Depth Information
Figure 20.2
CREATE TABLE
with Detailed
Constraints Syntax.
20.2.1.1
Primary Key and Unique Constraints
A unique constraint forces a column value to be unique within all rows of a
table. A primary key is forced to be a unique value and can reference foreign
key column values in subset tables.
Let's start by creating a table similar to the ARTIST table in the MUSIC
schema, using inline constraints.
CREATE TABLE ARTISTS(
ARTIST_ID NUMBER
PRIMARY KEY
, NAME VARCHAR2(32) NOT NULL
UNIQUE
);
Notice how the NAME column has the NOT NULL constraint
whereas the primary key column, ARTIST_ID, does not. The primary key
column has an inherent NOT NULL constraint. The primary key con-
straint has no name and is defined inline (for one specific column). The
unique constraint on the NAME column is also defined inline and has no
name. When no name is specified for the constraint, Oracle Database 10
g
will assign a name of its own.
 
Search WWH ::




Custom Search