常见的数据结构
二叉树
B Tree(多路搜索树)
- 树的深度 = 有几根线
- key 的数量 = 树的深度 - 1
B+Tree
- 跟多路搜索树不同的是,所有的节点都会在最下层的叶子节点中,并且形成链表
约束
约束是什么?
约束类型
主键约束
primary Key
- 类似于我们每个人的身份证,唯一且非空
- MySQL 的默认引擎 InnoDB 存储数据时,数据结构使用的是 B+ 树
- 数据存在聚集索引上,每个表都需要聚集索引,也就是主键
外键约束
非空约束
唯一性约束
默认值约束
如何创建约束
create table 身份证表(
id int primary key auto_increment,
身份证号 varchar(18) unique not null
);
create table 身份证信息表(
id int PRIMARY key auto_increment,
姓名 VARCHAR(20) not null,
年龄 int not null,
身份证号 varchar(18) not null,
婚姻状况 varchar(10) default '未婚',
constraint foreign key (身份证号) references 身份证表(身份证号)
);
验证约束
sql
复制代码
create table 身份证表(
id int primary key auto_increment,
身份证号 varchar(18) unique not null
);
create table 身份证信息表(
id int