Source:http://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php
What is a foreign key?
A foreign key means that values in one table must also appear in another table.
The referenced table is called the parent table while the table with the foreign key is called child table. The foreign key in the child table will generally references a primary key in the parent table.
[@more@]A foreign key with cascade delete means that if a record in the parent table is deleted, then the corresponding records in the child table will be automatically deleted. This is called cascade delete.
A foreign key with a cascade delete can be defined in either a CREATE TABLE statement or an ALTER TABLE statement.
The syntax for creating a foreign key using CREATE TABLE statement is:
CREATE TABLE table_name
(colum1 datatype null/not null,
colum2 datatype null/not null,
…
CONSTRAINT constraint_name
FOREIGN KEY (colum1, column2, … column_n)
REFERNCES parent_table(colum1, column2, … column_n)
ON DELETE CASCADE
);
The syntax for creating a foreign key using ALTER TABLE statement is:
ALTER TABLE table_name
add CONSTRAINT constraint_name
FOREIGN KEY (colum1, column2, … column_n)
REFERNCES parent_table(colum1, column2, … column_n)
ON DELETE CASCADE;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/119395/viewspace-897773/
,如需转载,请注明出处,否则将追究法律责任。