column list 1 | This list is columns in the current table that make up the foreign key columns. |
column list 2 | This list of columns is the primary key columns in the referenced table. You can leave this off if you wish. If left off, Oracle simply assumes that the entire primary key in its original order will be used. |
ON DELETE{CASCADE | If you include the ON DELETE CASCADE parameter, this means that when the parent row in the referenced table is deleted, the child rows in this table are deleted. |
SET NULL | If you include the ON DELETE SET NULL parameter, when a parent row is deleted, the child rows in this table have their foreign key data set to null values. |
] | Eliminating the ON DELETE parameter means that the parent row cannot be deleted if there are any child rows in this table. |
This is a variation on the syntax for creating a
FOREIGN KEY
constraint. It has several restrictions:
- You cannot name the foreign key yourself, you must allow the system to name it.
- The foreign key column must be one column.
Here is the syntax:
REFERENCES [user.]table [(column_name)]
[ ON DELETE { CASCADE | SET NULL} ]
Here is an example:
CREATE TABLE PET_CARE_LOG
(PRODUCT_ID NUMBER(10) REFERENCES PRODUCT
ON DELETE SET NULL,
LOG_DATETIME DATE,
LOG_TEXT VARCHAR2(500))
In this example, the PRODUCT_ID is a foreign key referencing the PRODUCT table. When the parent row (in PRODUCT) is deleted, the child row's PRODUCT_ID column is set to null.
A
check constraint[2] is a condition that is required for every row in the table. Each row's data must either have data that complies with the condition or have null values in the checked columns.
The MouseOver below describes the syntax for creating a
CHECK
constraint.