Foreign key (referential) constraints on DB2 LUW v105
oreign key constraints (also known as referential constraints or referential integrity constraints) enable you to define required relationships between and within tables.
For example, a typical foreign key constraint might state that every employee in the EMPLOYEE table must be a member of an existing department, as defined in the DEPARTMENT table.
- They appear as values of a parent key.
- Some component of the foreign key is null.
To establish this relationship, you would define the department number in the EMPLOYEE table as the foreign key, and the department number in the DEPARTMENT table as the primary key.
The table containing the parent key is called the parent table of the referential constraint, and the table containing the foreign key is said to be a dependent of that table.
Referential constraints can be defined in the CREATE TABLE statement or the ALTER TABLE statement. Referential constraints are enforced by the database manager during the execution of INSERT, UPDATE, DELETE, ALTER TABLE, MERGE, ADD CONSTRAINT, and SET INTEGRITY statements.
| Concept | Terms |
|---|---|
| Parent key | A primary key or a unique key of a referential constraint. |
| Parent row | A row that has at least one dependent row. |
| Parent table | A table that contains the parent key of a referential constraint. A table can be a parent in an arbitrary number of referential constraints. A table that is the parent in a referential constraint can also be the dependent in a referential constraint. |
| Dependent table | A table that contains at least one referential constraint in its definition. A table can be a dependent in an arbitrary number of referential constraints. A table that is the dependent in a referential constraint can also be the parent in a referential constraint. |
| Descendent table | A table is a descendent of table T if it is a dependent of T or a descendent of a dependent of T. |
| Dependent row | A row that has at least one parent row. |
| Descendent row | A row is a descendent of row r if it is a dependent of r or a descendent of a dependent of r. |
| Referential cycle | A set of referential constraints such that each table in the set is a descendent of itself. |
| Self-referencing table | A table that is a parent and a dependent in the same referential constraint. The constraint is called a self-referencing constraint. |
| Self-referencing row |
A row that is a parent of itself. |
The purpose of a referential constraint is to guarantee that table relationships are maintained and that data entry rules are followed. This means that as long as a referential constraint is in effect, the database manager guarantees that for each row in a child table that has a non-null value in its foreign key columns, a row exists in a corresponding parent table that has a matching value in its parent key.
- An insert rule
- An update rule
- A delete rule
- An insert operation could attempt to add a row of data to a child table that has a value in its foreign key columns that does not match a value in the corresponding parent table's parent key.
- An update operation could attempt to change the value in a child table's foreign key columns to a value that has no matching value in the corresponding parent table's parent key.
- An update operation could attempt to change the value in a parent table's parent key to a value that does not have a matching value in a child table's foreign key columns.
- A delete operation could attempt to remove a record from a parent table that has a matching value in a child table's foreign key columns.
- An insert rule
- An update rule
- A delete rule
Foreign key (referential) constraints on DB2 LUW v105的更多相关文章
- MySQL Foreign Key
ntroduction to MySQL foreign key A foreign key is a field in a table that matches another field of a ...
- InnoDB和Foreign KEY Constraints
InnoDB表中中Foreign Key定义 1. InnoDB允许a foreign key引用一个索引列或者索引组列. 2. InnoDB现在并不支持用户定义的分区表有foreign keys,这 ...
- Database Primary key and Foreign key [From Internet]
Database Primary key and Foreign key --Create Referenced Table CREATE TABLE Department ( DeptID int ...
- 数据库中的參照完整性(Foreign Key)
之前在项目中遇到了这样一个问题,我举得简单的样例来说明. 比方我们有两个表,一个表(department)存放的是部门的信息,比如部门id,部门名称等:还有一个表是员工表(staff),员工表里面肯定 ...
- oracle primary key & foreign key
主键:一个表中只有一个主键约束,但是一个主键约束可以由数据表中的多个列组成:primary key alter table TName add constraints pk_name PRIMARY ...
- Is it bad to rely on foreign key cascading? 外键 级联操作
Is it bad to rely on foreign key cascading? I'll preface前言 this by saying that I rarely delete rows ...
- SQL PRIMARY KEY,SQL FOREIGN KEY
A primary key is defined as a column or a group of column that their value are always be unique. Nor ...
- admin添加用户时报错:(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_l
在stackoverflow找到答案: DATABASES = { 'default': { ... 'OPTIONS': { "init_command": "SET ...
- foreign key
http://sevenseacat.net/2015/02/24/add_foreign_key_gotchas.html https://robots.thoughtbot.com/referen ...
随机推荐
- MySQL Python教程(1)
首先对于数据库的基本操作要有一定基础,其次了解Python的基础语法. 建议先阅读MysqL中文教程http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chap ...
- eclipse emacs
eclipse emacs 插件 http://www.mulgasoft.com/emacsplus eclipse字体设置: 一.把字体设置为Courier New 操作步骤:打开Elcipse ...
- php写入txt换行符
1.问题 写入txt文件想换行,老是直接输出了\r\n. 2.解决 要用双引号对\r\n进行解释,否则php会直接当字符输出. 3.例子 要求:往test.txt文本每一行后面加abc $a=file ...
- iOS中的时间和日期
怎么说?时间和日期不是了不起的属性.了不起的功能,但是,我们决不能够因此就“冷落”它. 一:怎么“搞到货”--如何获取时间.日期 //-=-==当前时间------默认显示“0时区”时间 NSDate ...
- Android列表控件ListView详解
ListView绝对可以称得上是Android中最常用的控件之一,几乎所有应用程序都会用到它. 由于手机屏幕空间都比较有限,能够一次性在屏幕上显示的内容并不多,当我们的程序中有大量的数据需要展示的时候 ...
- POJ 1995 快速幂模板
http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include< ...
- Python PEP8规范
转载自:http://blog.csdn.net/kellyseeme/article/details/50644893 风格指南:http://zh-google-styleguide.readth ...
- Java Log4j日志使用
在程序中使用log4j 1.导入包import org.apache.log4j.Logger;import org.apache.log4j.PropertyConfigurator; 2.获取lo ...
- JAVA上百实例源码以及开源项目
简介 笔者当初为了学习JAVA,收集了很多经典源码,源码难易程度分为初级.中级.高级等,详情看源码列表,需要的可以直接下载! 这些源码反映了那时那景笔者对未来的盲目,对代码的热情.执着,对IT的憧憬. ...
- wireshark 和 Httpwatch tcpdump
wireshark 功能强大,适用性高.过滤功能好. Httpwatch 功能单一,优缺点明显,但是非常适合抓取http交互的包,而且可以非常明确的显示出整个的交互过程. tcpdump linux ...