码迷,mamicode.com
首页 > 数据库 > 详细

mysql8.0 外键

时间:2019-06-27 01:05:42      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:class   set   student   _id   char   sid   utf8   ODB   incr   

一、外键

constraint 名称  foreign key()  references 表名()

create table student(
    sid int auto_increment primary key,
    sname char(10),
    gender char(5),
    class_id int,
    constraint stu_key foreign key(class_id) references class(cid)
    )engine=innodb default charset=utf8;

二、唯一索引

unique 名称 (列)

联合唯一

三、外键变种

1、一对多

2、一对一

3、多对多(额外创建一张表)

mysql8.0 外键

标签:class   set   student   _id   char   sid   utf8   ODB   incr   

原文地址:https://www.cnblogs.com/wt7018/p/11094474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!