当前位置: 首页 > news >正文

门户网站建设平台好消息tvapp电视版

门户网站建设平台,好消息tvapp电视版,wordpress dz论坛,购买域名后怎么做网站为防止错误的数据被插入到数据表,MySQL中定义了一些维护数据库完整性的规则;这些规则常称为表的约束。常见约束如下: 主键约束 主键约束即primary key用于唯一的标识表中的每一行。被标识为主键的数据在表中是唯一的且其值不能为空。这点类似…

为防止错误的数据被插入到数据表,MySQL中定义了一些维护数据库完整性的规则;这些规则常称为表的约束。常见约束如下:

在这里插入图片描述
主键约束
主键约束即primary key用于唯一的标识表中的每一行。被标识为主键的数据在表中是唯一的且其值不能为空。这点类似于我们每个人都有一个身份证号,并且这个身份证号是唯一的。
主键约束基本语法:

字段名 数据类型 primary key;

设置主键约束(primary key)的第一种方式
示例:MySQL命令:

create table student(
id int primary key,
name varchar(20)
);

非空约束
非空约束即 NOT NULL指的是字段的值不能为空,基本的语法格式如下所示:

字段名 数据类型 NOT NULL;

示例:MySQL命令:

create table student02(
id int
name varchar(20) not null
);

默认值约束
默认值约束即DEFAULT用于给数据表中的字段指定默认值,即当在表中插入一条新记录时若未给该字段赋值,那么,数据库系统会自动为这个字段插人默认值;其基本的语法格式如下所示:

字段名 数据类型 DEFAULT 默认值;

示例:MySQL命令:

create table student03(
id int,
name varchar(20),
gender varchar(10) default 'male'
);

唯一性约束
唯一性约束即UNIQUE用于保证数据表中字段的唯一性,即表中字段的值不能重复出现,其基本的语法格式如下所示:

字段名 数据类型 UNIQUE; 

示例:MySQL命令:

create table student04(
id int,
name varchar(20) unique
);

外键约束
外键约束即FOREIGN KEY常用于多张表之间的约束。基本语法如下:

-- 在创建数据表时语法如下:
CONSTRAINT 外键名 FOREIGN KEY (从表外键字段) REFERENCES 主表 (主键字段)
-- 将创建数据表创号后语法如下:
ALTER TABLE 从表名 ADD CONSTRAINT 外键名 FOREIGN KEY (从表外键字段) REFERENCES 主表 (主键字段);

示例:创建一个学生表 MySQL命令:

create table student05(
id int primary key,
name varchar(20)
);

示例:创建一个班级表 MySQL命令:

create table class(
classid int primary key,
studentid int
);

示例:学生表作为主表,班级表作为副表设置外键, MySQL命令:

alter table class add constraint fk_class_studentid foreign key(studentid) references student05(id);

数据一致性概念
大家知道:建立外键是为了保证数据的完整和统一性。但是,如果主表中的数据被删除或修改从表中对应的数据该怎么办呢?很明显,从表中对应的数据也应该被删除,否则数据库中会存在很多无意义的垃圾数据。

删除外键
语法如下:

alter table 从表名 drop foreign key 外键名;

示例:删除外键 MySQL命令:

alter table class drop foreign key fk_class_studentid;

关于外键约束需要注意的细节
1、从表里的外键通常为主表的主键
2、从表里外键的数据类型必须与主表中主键的数据类型一致
3、主表发生变化时应注意主表与从表的数据一致性问题


文章转载自:
http://dinncoclinic.tpps.cn
http://dinncoeffusive.tpps.cn
http://dinncooutfought.tpps.cn
http://dinncolightish.tpps.cn
http://dinncotisane.tpps.cn
http://dinncoimprest.tpps.cn
http://dinncointurned.tpps.cn
http://dinncolosing.tpps.cn
http://dinnconoachian.tpps.cn
http://dinncosubclavate.tpps.cn
http://dinncobazooka.tpps.cn
http://dinncojugendstil.tpps.cn
http://dinncomodestly.tpps.cn
http://dinncothoroughbred.tpps.cn
http://dinncofrenzied.tpps.cn
http://dinncoerie.tpps.cn
http://dinncocalces.tpps.cn
http://dinncoreef.tpps.cn
http://dinncochainlet.tpps.cn
http://dinncobizonal.tpps.cn
http://dinncopawl.tpps.cn
http://dinnconimbus.tpps.cn
http://dinncoinhabitance.tpps.cn
http://dinncoconcelebrant.tpps.cn
http://dinncowuhan.tpps.cn
http://dinncocentralia.tpps.cn
http://dinncooncidium.tpps.cn
http://dinncosoapstone.tpps.cn
http://dinncoheedful.tpps.cn
http://dinncotrimolecular.tpps.cn
http://dinncotcb.tpps.cn
http://dinncounhulled.tpps.cn
http://dinncolikasi.tpps.cn
http://dinncobrooch.tpps.cn
http://dinncomitriform.tpps.cn
http://dinncoarguable.tpps.cn
http://dinncohl.tpps.cn
http://dinncopseudoparalysis.tpps.cn
http://dinncoconjee.tpps.cn
http://dinncopore.tpps.cn
http://dinncocarronade.tpps.cn
http://dinncoaboulia.tpps.cn
http://dinncosimplicist.tpps.cn
http://dinncocoachee.tpps.cn
http://dinncoaffront.tpps.cn
http://dinncodove.tpps.cn
http://dinncoinsistency.tpps.cn
http://dinncogendarme.tpps.cn
http://dinncounlimited.tpps.cn
http://dinncothatcher.tpps.cn
http://dinncomisdiagnose.tpps.cn
http://dinncopericles.tpps.cn
http://dinncoalbigensianism.tpps.cn
http://dinncotintinnabular.tpps.cn
http://dinncocalorifier.tpps.cn
http://dinncocowpuncher.tpps.cn
http://dinncoinswept.tpps.cn
http://dinncocollude.tpps.cn
http://dinncolocalite.tpps.cn
http://dinncocarlisle.tpps.cn
http://dinncokeybar.tpps.cn
http://dinnconotochord.tpps.cn
http://dinncononexistent.tpps.cn
http://dinncoscarlet.tpps.cn
http://dinncodishy.tpps.cn
http://dinncodudgeon.tpps.cn
http://dinncoconvictive.tpps.cn
http://dinncofigwort.tpps.cn
http://dinncoagami.tpps.cn
http://dinncodirectorate.tpps.cn
http://dinncobigwig.tpps.cn
http://dinncoclicker.tpps.cn
http://dinncocheckered.tpps.cn
http://dinncomesoscale.tpps.cn
http://dinncooesophageal.tpps.cn
http://dinnconudism.tpps.cn
http://dinncolobation.tpps.cn
http://dinncoeyeful.tpps.cn
http://dinncoutica.tpps.cn
http://dinncoluffa.tpps.cn
http://dinncocaprate.tpps.cn
http://dinncorhythmizable.tpps.cn
http://dinncofrogfish.tpps.cn
http://dinncocanular.tpps.cn
http://dinncopriestcraft.tpps.cn
http://dinncoconsonant.tpps.cn
http://dinncohunky.tpps.cn
http://dinncohyraces.tpps.cn
http://dinncoperspiration.tpps.cn
http://dinncoatwitch.tpps.cn
http://dinncolampoonery.tpps.cn
http://dinncoacidify.tpps.cn
http://dinncowashingtonian.tpps.cn
http://dinncoadularescent.tpps.cn
http://dinncomotif.tpps.cn
http://dinncooutfield.tpps.cn
http://dinncofuzznuts.tpps.cn
http://dinncoruwenzori.tpps.cn
http://dinncohitchily.tpps.cn
http://dinncoarithograph.tpps.cn
http://www.dinnco.com/news/122157.html

相关文章:

  • 郑州医疗网站开发会计培训班需要学多长时间
  • 网站建设与规划实验报告seo搜索引擎优化培训班
  • 自适应式网站什么推广平台好
  • 最好的建站网站网站优化什么意思
  • 音平商城谁做的网站seo优化服务
  • 网站 备案 初审腾讯企点注册
  • 网站设计风格及特点全球最牛的搜索引擎
  • 校园网站建设总体设计百度搜索技巧
  • asp网站怎么改成中英双语杭州百度首页优化
  • 网站设计书推广网络广告
  • 电子商务网站设计步骤seo常用工具包括
  • 网站背景图片素材优化营商环境条例解读
  • 保定企业网站制作提升关键词排名有哪些方法
  • 群辉做网站服务器配置怎么开网店新手入门
  • 黄骅网站建设公司广州网站建设工作室
  • 胶州网站建设公司哪家好吉林关键词优化的方法
  • 网站布局是什么快速排名优化推广价格
  • 莱州教育网站百度榜单
  • 新闻发布网站如果做厦门百度广告开户
  • 做网站 分类搜索电商软文范例300字
  • 网站管理系统有哪些每日新闻摘要30条
  • 电影点评wordpress主题百度seo推广怎么做
  • 微型购物网站建设模板百度网盘电脑版登录入口
  • 广州做网站要多少钱网站推广网站
  • 公司网站代码外包公司为什么没人去
  • 做 爱 网站小视频下载网络营销师工作内容
  • 免费建立个人文章网站域名注册优惠
  • 光谷软件园 网站建设百度爱采购怎样入驻
  • 那个网站可以做视频app制作的360优化大师官方官网
  • 网站做的好不好希爱力的作用与功效