Database Reference
In-Depth Information
locating them after the column definitions is the most commonly used
method. All of these out-of-line constraints have names.
Note how the primary key constraint (named PKCDTRACKS) names
two columns: MUSICCD_ID and SONG_ID. A primary key with multi-
ple columns is sometimes called a
.
The two foreign keys have also been created at table level for the sake of
consistency, even though they are both single-column keys.
composite primary key
Note:
The same column can be named in a primary key and a foreign key.
Now let's try something interesting going through a sequence of steps.
Drop and re-create the CDTRACKS table as in the following script. We are
adding a new column, called TRACK_ID, which will become the primary
key later. Note how all the columns are now declared as nullable because all
NOT NULL constraints have been removed. Also, both the primary and
foreign keys have been removed.
DROP TABLE CDTRACKS;
CREATE TABLE CDTRACKS(TRACK_ID NUMBER, MUSICCD_ID NUMBER
, SONG_ID NUMBER, TRACK_SEQ_NO NUMBER);
The resulting table's description using the DESC command is shown in
Figure 20.3. All of the columns in the CDTRACKS table are allowed to
contain null values.
Figure 20.3
The CDTRACKS
Copy of the
CDTRACK Table
with No
Constraints.
Search WWH ::




Custom Search