Home Database Mysql Tutorial Oracle级联操作详解

Oracle级联操作详解

Jun 07, 2016 pm 04:08 PM
o oracle database

在添加foreing key约束时,还可以指定级联操作的类型,主要用于确定当删除(on delete) 附表中的一条记录时,如何处理子表中的外

在添加foreing key约束时,还可以指定级联操作的类型,主要用于确定当删除(on delete) 附表中的一条记录时,如何处理子表中的外键字段,有如下三种引用类型。

cascade
此关键字用于表示当删除主表中被引用列的数据时,将子表中相应应用列的值置为null值,这种情况要求子表中的引用列支持null值
set null
此关键字用于当删除主表中被引用列的数据时,将子表中相应引用列的值设置为null值。这种情况要求子表中的应用列支持null值。
not action
此关键字用于表示当删除主表中被引用的数据时,,如果子表的引用列种包含该值,则禁止操作执行。默认为该选项。

具体的操作如下:
SQL> create table stuclass(
  2  cid number(4) primary key,
  3  cname varchar2(40),
  4  num number(4)
  5  );
表已创建。
SQL> create table stu(
  2  sid number(4),
  3  scode varchar(10),
  4  sname varchar(20),
  5  cid number(4) references stuclass(cid) on delete set null
  6  );
表已创建。
SQL> insert into stuclass values(1,'Oracle',35);
已创建 1 行。
SQL> insert into stu values(1,'s001','aaa',1);
已创建 1 行。
SQL> delete stuclass where cid=1;
已删除 1 行。
SQL> select * from stuclass;
未选定行
SQL> select * from stu;
      SID SCODE      SNAME                      CID
---------- ---------- -------------------- ----------
        1 s001      aaa
SQL>

Oracle级联操作

本文永久更新链接地址

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

How to use database callback functions in Golang?

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

How to handle database connection errors in PHP

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Mar 12, 2025 pm 05:48 PM

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking)

How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

How to install and register the btc trading app?

Redstone/RED currency listing price forecast and detailed explanation of token economics Redstone/RED currency listing price forecast and detailed explanation of token economics Mar 03, 2025 pm 10:42 PM

Redstone/RED currency listing price forecast and detailed explanation of token economics

See all articles