Database Reference
In-Depth Information
Now let's put the table-level primary and foreign key constraints back
into the creation of the CDTRACKS table without the NOT NULL con-
straints and see what happens to the nullability of the columns. This time,
we will name the TRACK_ID column as the primary key and keep the for-
eign key constraints the same as before.
These commands drop the table and create it with primary and foreign
keys. There are no NOT NULL constraints added.
DROP TABLE CDTRACKS;
CREATE TABLE CDTRACKS(TRACK_ID NUMBER, MUSICCD_ID NUMBER
, SONG_ID NUMBER, TRACK_SEQ_NO NUMBER
, CONSTRAINT PKCDTRACKS PRIMARY KEY (TRACK_ID)
, CONSTRAINT FKCDTRACKS_SONG
FOREIGN KEY (SONG_ID) REFERENCES SONGS
, CONSTRAINT FKCDTRACK_CD
FOREIGN KEY (MUSICCD_ID) REFERENCES MUSICCD);
Now let's view the CDTRACKS table again using the DESC command
as shown in Figure 20.4.
Notice in Figure 20.4 how the primary key column has been forced to
have the NOT NULL constraint, even though the NOT NULL constraint
was not specified for the column when creating the CDTRACKS table.
The foreign key columns still remain nullable.
Figure 20.4
A NOT NULL
Constraint Is
Automatically
Added to the
Primary Key
Column.
 
Search WWH ::




Custom Search