Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1404554
  • 博文数量: 556
  • 博客积分: 12626
  • 博客等级: 上将
  • 技术积分: 5799
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-11 15:56
个人简介

从事IT基础架构多年,发现自己原来更合适去当老师……喜欢关注新鲜事物,不仅限于IT领域。

文章分类

全部博文(556)

文章存档

2019年(6)

2018年(15)

2017年(17)

2016年(11)

2015年(2)

2014年(2)

2013年(36)

2012年(54)

2011年(100)

2010年(41)

2009年(72)

2008年(14)

2007年(82)

2006年(104)

分类: Oracle

2006-02-14 10:13:08

on delete子句可以保证数据的一致性,如下例中,删除t1表记录时,相应的t2表记录将被删除:

create table a_t1(id int primary key,name varchar(20));
create table a_t2(id int primary key references a_t1(id) on delete cascade,qty number)

对于on delete子句的解释如下:

ON DELETE Clause

The ON DELETE clause lets you determine how Oracle automatically maintains referential integrity if you remove a referenced primary or unique key value. If you omit this clause, then Oracle does not allow you to delete referenced key values in the parent table that have dependent rows in the child table.

  • Specify CASCADE if you want Oracle to remove dependent foreign key values.
  • Specify SET NULL if you want Oracle to convert dependent foreign key values to NULL.

CREATE TABLE dept_20
   (employee_id     NUMBER(4) PRIMARY KEY,
    last_name       VARCHAR2(10),
    job_id          VARCHAR2(9),
    manager_id      NUMBER(4) CONSTRAINT fk_mgr
                    REFERENCES employees ON DELETE SET NULL,
    hire_date       DATE,
    salary          NUMBER(7,2),
    commission_pct  NUMBER(7,2),
    department_id   NUMBER(2)   CONSTRAINT fk_deptno
                    REFERENCES departments(department_id)
                    ON DELETE CASCADE );

 

阅读(785) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~