数据库:唯一性约束
所谓唯一性约束(unique constraint)不过是数据表内替代键的另一个名称而已。替代键(alternate key)可以是数据表内不作为主键的其他任何列,只要该键对该数据表唯一即可。换句话说,在唯一列内不允许出现数据重复的现象。比方说,你可以用车辆识别代号(VIN)作为汽车(Automobile)数据表的替代键,在汽车数据表里,主键是汽车识别号(Automobile Identification),这是一种由系统自动生成的ID。你可以在汽车表内对VIN施加唯一性约束,同时再创建一个需要VIN的表。在这个新表内可以声明外键指向汽车表。这样,只要汽车表内有VIN输入数据库就会检验VIN输入结果。这就是保证数据库内数据完整性的另一种有效的措施。
create table parent
(parent_id int not null, -- Primary key
parent_alternate_key int not null, -- Alternate key
parent_col1 int null,
parent_col2 int null,
constraint pk_parent_id primary key (parent_id),
constraint ak_parent_alternate_key unique_
(parent_id, parent_alternate_key)
使用约束:
create table child2
(child2_parent_id int not null, -- Primary key/Foreign key
child2_id int not null, -- Primary key
child2_col1 int null,
child2_parent_alternate_key int not null, -- Foreign key
constraint pk_child2 primary key (child2_parent_id, child2_id),
constraint fk_child2_parent foreign key (child2_parent_id)
references dbo.parent(parent_id),
constraint fk_pk_ak_child2_parent foreign key _
(child2_parent_id, child2_parent_alternate_key) _
references dbo.parent(parent_id, parent_alternate_key)
primary key 与UNIQUE的区别
1.一个基本表中只能定义一个primary key,但可以定义多个UNIQUE的约束
2.指定primary key的一个列或多个列的组合都不能为NULL,而UNIQUE所约束的唯一键则允许为空
3.不能为一个列或多个列既定义primary key,又定义UNIQUE约束
MYSQL目前不支持外键,其理由如下:
1.外键使生活更复杂,因为外键的定义必须存储在一个数据库中并且实现他们将破坏使用能被移动、拷贝和删除文件的全部“好方法”。
2.速度影响对INSERT和UPDATE语句是可怕的,并且在这种情况下几乎所有的FOREIGN KEY检查都是无用的,因为不管怎样你通常以正确的顺序在正确的表中插入记录。
3.当更新一张表时,也有在许多表上保存锁的需求,因为副作用可以串联通过全部数据库。首先从一张表中删除记录并且随后从其他表中删除他们,这更快。
4.你再也不可以通过做一个全面的表删除并随后恢复所有的记录的方法来恢复一张表(从新来源或从一个备份)。
5.如果你有外键,你不能倾倒和恢复表,除非你以一个非常特定的做这些。
6.很容易做一个“允许的”的循环定义使得不可能用一个单个create语句重建每一个表,就算定义可行又可用。
分享到:
相关推荐
gem 'spree_alternate_prices' , github : 'aegixx/spree_alternate_prices' , branch : '2-4-stable' 捆绑您的依赖项: bundle (可选)这是建立在 spree_multi_currency 之上的,所以首先运行该安装生成器...
__[ExStudPE_V1.6.4.3_ALTERNATE_最终完整版_含全部插件.7z]__ ----------------------------------------- ExStudPE Visual Tools 使用说明 ~ 强大的PE/PE64/NE/LE/COFF/LIB/ELF 格式分析、调试、编辑工具 ~ ...
用来建立数据库连接的唯一服务名。如果要在没有调度程序的情况下仍能连接到数据库, 请将该值设置为与例程名相同。此参数自 8.1.3 版起已废弃。 值范围: 根据操作系统而定。 默认值 :0 mts_sessions: 说明 : 指定...
Alternate path between any two node
The files here are gzipped tar files of examples and ...how alternate solutions to a programming problem can all be "correct". Thanks for your interest, and good luck with the material! Sincerely, Jim
javascript-image_alternate_text 返回图像的替代文本。
NULL 博文链接:https://paddy-w.iteye.com/blog/792674
link rel=alternate media=only screen and(max-width: 640px) href=http://pc_url > 在移动版网页(http://mobile_url) 上,所需的注释应为: <link rel=canonical href=http://mobile_url > 之前的Meta...
和名字的意思一样,此函数设置当前设备配置的interface descriptor,参数alternate是指interface descriptor中的bAlternateSetting。返回0成功,失败 usb_resetep 函数定义: int usb_resetep(usb_dev_handle ...
Candidate key(候选键,ER关系模型):仅包含唯一标识实体所必须得最小数量的属性/列的 超键。 14. Cardinality(基数):描述每个参与实体的可能的关系数目。 15. Centralized approach(集中化方法,用于数据库...
AS主题包:Solarized Light (Alternate).jar…………………………
2. For each table, indicate the Alternate Key(s) (AKs). If there is no AK, state so. Fully justify your answer. 3. For each table, identify the Foreign Key(s) (FKs) and the integrity constraints. ...
{ Set RPi GPIO pin to alternate function nr. 0..5 } procedure gpio_set_gppud (mask:longword); { set RPi GPIO Pull-up/down Register (GPPUD) with mask } ... function rpi_snr :string; { delivers SNR: ...
文件包括:initrd.gz、vmlinuz、menu.lst、grldr、grub.exe。...注意:此内核文件是为Alternate版本的,如果安装Desktop版本,请直接从ISO中解压出这两个文件来替换,然后修改menu.lst文件中最后的initrd.gz为initrd.lz
max485 alternate to set fast gpio on stm32 and leds
name : ' Auto Assign 'on : pull_request types : [opened, ready_for_review]jobs : add-reviews : runs-on : ubuntu-latest steps : - uses : luisliuchao/alternate-assign-action@v1.1.2 with : configuration...
simple_sv_annotation.py 简化snpEff批注的工具 目录 要求 python 2.7 Python模块 带有注释的文件。...--exonNums/-e FILE - List of custom exon numbers (see Alternate Exon Numbers) -r - Re
知识图谱包含disease、alternate_name、pathogenic_site、department、symptom 、check、susceptible_crowd等实体类型和disease_alternate_nam、disease_pathogenic_site 、disease_symptom、disease_check、disease...
HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...