登录  /  注册

mysql数据库学习――4,完整性约束_MySQL

php中文网
发布: 2016-06-01 13:32:01
原创
1262人浏览过

bitsCN.com

mysql数据库学习——4,完整性约束

 

主键

create table feng(teamno int not null,playerno int not null,pision char(6) not null,primary key(teamno))create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,)
登录后复制

复合主键

create table feng(teamno int not null,playerno int not null,pision char(6) not null,primary key(teamno,playerno))
登录后复制

替代键(候选键)

create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,unique(playerno))create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,unique(playerno,pision))
登录后复制

外键(在innoDB中使用)

外键声明包括三个部分

1,那个列或列组合是外键

2,指定外键参照的表和列

3,参照动作[cascade(级联操作),restrict(拒绝操作),set null(设为空),no action,set default]

如果没有指定参照动作默认是

on update restricton delete  restrictcreate table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,foreign key(pision)references othertable   (column)on update restrictunique(playerno))check完整性约束create  table players (playerno int not null, sex   char(1) not null,         check (sex in (&#39;m&#39;,&#39;f&#39;)))create  table players (playerno int not null,birth_date  date, sex   char(1) not null,         check (sex in (&#39;m&#39;,&#39;f&#39;))joined smallint not null,             check (year(birth_date)<joined),             check (joined<1880),)create  table players (playerno int not null,birth_date  date, sex   char(1) not null,          check (sex in (select sex from wholetab))
登录后复制

 


bitsCN.com
智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号