background image
<< Using the Add Foreign Key Window | Adding Data to a Table, Modifying, and Deleting >>
<< Using the Add Foreign Key Window | Adding Data to a Table, Modifying, and Deleting >>

Adding a Check Constraint

Creating and Using Tables
3-12 Oracle Database 2 Day Developer's Guide
REFERENCES "HR"."PERFORMANCE_PARTS" ("PERFORMANCE_ID") ENABLE
In
Example 3­5
, you will create a foreign key constraint on the
evaluations
table by
entering the required information directly in the SQL Statement window.
Example 3­5 Adding a Foreign Key Constraint in SQL Script
ALTER TABLE evaluations
ADD CONSTRAINT eval_emp_id_fk FOREIGN KEY (employee_id)
REFERENCES employees(employee_id);
The results of the script follow.
ALTER TABLE evaluations succeeded
You have now created a foreign key constraint on the
employee_id
column from the
employees
table. If you click the SQL tab, you will see the following SQL statement
was added to your table definition. You may need to click the Refresh icon.
CONSTRAINT "EVAL_EMP_ID_FK" FOREIGN KEY ("EMPLOYEE_ID")
REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ENABLE
To add a check constraint using the SQL Developer interface:
You will add a check constraint to the
scores
table using the SQL Developer
graphical interface. You could also use the Edit Table window, as in the
NOT NULL
constraint, to accomplish this task.
1.
In the Connections navigation hierarchy, the plus sign (+) next to Tables to expand
the list of tables.
2.
Right-click the
scores
table.
3.
Select Constraint, and then select Add Check.
4.
In the Add Check window, enter the following information:
Set the Constraint Name to
SCORE_VALID
.
Set Check Condition to
score >=0 and score <=9
.
Set Status to
ENABLE
.
Click Apply.