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 ...
随机推荐
- phpcms中常用代码总结
1.调用数据库模型 $this->db = pc_base::load_model('test_model');//从"phpcms/model/"目录下加载模型类文件 其中 ...
- MongoDB 基础知识
一. 基础知识 1. MongoDB是一个文档型的数据库,文档就是一个键值对的有序集合. 例如这样:{"greeting":"hello world"} 2. ...
- 教你如何在Kali Linux 环境下设置蜜罐?
导读 Pentbox是一个包含了许多可以使渗透测试工作变得简单流程化的工具的安全套件.它是用Ruby编写并且面向GNU/Linux,同时也支持Windows.MacOS和其它任何安装有Ruby的系统. ...
- Unity3D性能优化--- 收集整理的一堆
http://www.cnblogs.com/willbin/p/3389837.html 官方优化文档--优化图像性能http://docs.unity3d.com/Documentation/Ma ...
- BZOJ 3907: 网格
Description 求不跨过直线 \(y=x\) ,到达 \((n,m)\) 的方案数. Sol 组合数学+高精度. 这个推导过程跟 \(Catalan\) 数是一样的. 答案就是 \(C^{n+ ...
- PyQt4多线程定时刷新控件
1.通过事件关联和线程关联的方法刷新控件 self.listview=updatelistview()self.listview.updateText.connect(self.viewlist) ...
- symfony2 环境搭建笔记
本机环境:windows+xampp symfony下载:官网下载 环境配置: 1.下载后将symfony文件夹解压到xampp/htdocs中(最好改一下文件夹名,尽量小写) 2.Symfony2自 ...
- 使用keepalived及典型应用
通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务. eg:当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,而且切换的时间非常短.栗子:下面来以keepaliv ...
- [转]IntelliJ Idea 常用快捷键 列表(实战终极总结!!!!)
IntelliJ Idea 常用快捷键 列表(实战终极总结!!!!) ntelliJ Idea 常用快捷键 列表(实战终极总结!!!!) 1. -----------自动代码-------- 常用的有 ...
- HttpServletRequest中得到各种信息
1.获得domain: StringBuffer url = request.getRequestURL(); String domain = url.delete(url.length() - re ...