官术网_书友最值得收藏!

Entity integrity constraint

In the relational model, a relation is defined as a set of tuples. This means that all the tuples in a relation must be distinct. The entity integrity constraint is enforced by having a primary key, which is an attribute/set of attributes with the following characteristics:

  • The attribute should be unique
  • The attributes should be not null

Each relation must have only one primary key, but can have many unique keys. A candidate key is a minimal set of attributes that can identify a tuple. All unique, not null attributes can be candidate keys. The set of all attributes form a super key. In practice, we often pick up a single attribute to be a primary key instead of a compound key (a key that consists of two or more attributes that uniquely identify a tuple) to simplify the joining of the relations with each other.

If the primary key is generated by the DBMS, then it is called a surrogate key or synthetic key. Otherwise, it is called a natural key. The surrogate key candidates can be sequences and universal unique identifiers (UUIDs). A surrogate key has many advantages such as performance, requirement change tolerance, agility, and compatibility with object-relational mappers. The chief disadvantage of surrogate keys is that it makes redundant tuples possible. 

A sequence is a number generator that is used to generate a series of numbers based on the current number's value. This term is used mainly in PostgreSQL and Oracle databases. PostgreSQL also has an  identity column, which is mainly used to generate series of numbers. More about this topic is explained in Chapter 4, PostgreSQL Advanced Building Blocks.
主站蜘蛛池模板: 兴宁市| 莎车县| 垣曲县| 鄂托克前旗| 茂名市| 西乌珠穆沁旗| 澄迈县| 武城县| 沁源县| 紫金县| 厦门市| 曲麻莱县| 炎陵县| 长阳| 泰顺县| 清徐县| 景德镇市| 玉门市| 咸宁市| 迁安市| 绍兴市| 龙陵县| 沧州市| 石家庄市| 兴义市| 黎平县| 左贡县| 甘谷县| 卓尼县| 永善县| 泸州市| 临夏市| 获嘉县| 通山县| 阜宁县| 扎赉特旗| 田阳县| 罗定市| 明光市| 手游| 八宿县|