Oracle/PLSQL: Foreign key with cascade delete

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博客 ” ,链接:http://blog.itpub.net/119395/viewspace-897773/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/119395/viewspace-897773/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值