当前位置:网站首页>黑马数据库笔记DCL
黑马数据库笔记DCL
2022-07-13 17:55:00 【springxing星】
约束:
约束的概念和分类
1.约束的概念
①约束是作用于表中列上的规则,用于限制加入表的数据
②约束的存在保证了数据库中数据的正确性,有效性和完整性
2.约束的分类
约束名称 描述 关键字
非空约束 保证列中所有数据不能有null值 not null
唯一约束 保证列中所有数据各不相同 unique
主键约束 主键是一行数据的唯一标识,要求非空且唯一 primary key
检查约束 保证列中的值满足某一条件 check
默认约束 保存数据时,未指定值则采用默认值 default
外键约束 外键用来让两个表的数据之间建立链接保证数据的一致性和完整性 foreign key
自助增长(加主键里) auto_increment
tips:MYSQL不支持检查约束
外键约束
1.概念
外键用来让两个表的数据之间建立链接,保证数据的一致性和完整性
2.语法
(1)添加约束
--创建表时添加外键约束
create table 表名(
列名 数据类型;
)
constraint 外键名称 foreign key (外键列名) references 主表 (主表列名)
alter table 表名 add constraint 外键名称 foreign key (外键列名) references 主表 (主表列名)
(2)删除约束
alter table 表名 drop foreign key 外键名称
边栏推荐
- General operation of computer
- Typescript basic configuration tutorial (automatically compiled in vscode)
- [introduction to go language] 08 go language array
- 在Colab上训练yolov3(一)
- [introduction to go language] 09 detailed explanation of go language slice
- vant Weapp组件库中 自定义修改van-button 按钮宽高大小
- STM32F103 guider - example game Tetris
- Chapter III use of ld3320 speech recognition module
- Embedded software development stm32f407 key input standard library version
- A complete collection of C language preprocessing instructions
猜你喜欢

Excel-1

DHT11和DHT22(AM2302)比较及使用方法

How to make electronic signature transparent

Théorie de la distribution

VScode设置语言为中文,并且解决中文注释乱码问题。
![[Go语言入门] 05 Go语言分支语句](/img/cb/9830418c0e14b40fb15cfb68966426.png)
[Go语言入门] 05 Go语言分支语句

Introduction to STM32 GPIO details

Supervisor series: 4. Sub process
![[Go语言入门] 10 Go语言Map详解](/img/ac/dde4a9aac8de9b4e364eb9322945b4.png)
[Go语言入门] 10 Go语言Map详解
![[signal conditioning] example of precision detection circuit and PCB](/img/22/d5b2df49f9a642afda506b5fce0329.png)
[signal conditioning] example of precision detection circuit and PCB
随机推荐
I learned JWT single sign on with a cup of tea
[Go语言入门] 08 Go语言数组
整理numpy
RAC 心跳异常(ipReamsfails)的处理记录和分析
ArkUI路由跳转概览
Various operations of binary tree (leaf node, parent node, search binary tree, delete node in binary tree, depth of binary tree)
[hbuilderx development uniapp] automatic code formatting plug-in installation and configuration
ROS 通信机制
01-kNN
[matlab] matlab lesson 2 - preliminary drawing
语音芯片JQ8400的使用心得
[Go语言入门] 09 Go语言切片详解
Chapter 4 stm32+ld3320+syn6288+dht11 realize voice acquisition of temperature and humidity values (Part 1)
vant Weapp组件库中 自定义修改van-button 按钮宽高大小
Pagoda panel creates multiple port deployment projects under the same server (lightweight application server one click deployment website, blog, gltlab full version)
Spark入门
How to set the Internet function of raspberry pie
Friendly zeropi uboot, kernel compilation,
Pyopencv basic operation guide
GY-53红外激光测距模块的使用以及pwm模式代码的实现