Database Reference
In-Depth Information
Add a foreign key constraint to the SONGS table on the ARTIST_ID
column, referencing the ARTISTS table:
ALTER TABLE SONGS ADD CONSTRAINT FK_ARTISTS
FOREIGN KEY(ARTIST_ID) REFERENCES ARTISTS;
Add a unique constraint to the SONGS table on the TITLE column.
This constraint will be given a system-generated name because the CON-
STRAINT keyword is omitted.
ALTER TABLE SONGS ADD UNIQUE(TITLE);
20.3.3.2
Modifying Constraints on Existing Tables
Let's modify the ARTISTS and SONGS tables to make sure that names and
titles are non-nullable.
ALTER TABLE ARTISTS MODIFY (NAME VARCHAR2(32) NOT NULL);
ALTER TABLE SONGS MODIFY (TITLE VARCHAR2(64) NOT NULL);
Note: When changing constraints other than the NULL constraint, only
the state of a constraint can be modified.
This leads us to constraint states.
20.3.3.3
Constraint States
The state of a constraint determines how a constraint is handled. Each of
the constraint settings following applies to an individual constraint placed
onto a table. Most but not all constraint states can be set using all of the
CREATE TABLE, CREATE VIEW, ALTER TABLE, and ALTER VIEW
commands. Several constraint states are very specific.
ENABLE | DISABLE . Switch constraint checking on (ENABLE) or
off (DISABLE), for a specific constraint. ENABLE is obviously the
default state.
[NO]VALIDATE . This state applies when a constraint is enabled.
VALIDATE column values in a table for both existing and newly
inserted rows. NOVALIDATE validates only new rows, avoiding
validation of already existing rows. Validation depends on the con-
straint being enabled (ENABLE). VALIDATE is the default state.
 
Search WWH ::




Custom Search