mysql8.0版本中添加表级约束外键失败原因之⼀ 1create table if not exists t_classes(
2 classes_id int(3),
3 classes_name varchar(40),
4constraint pk_classes_id primary key(classes_id)
5 );
6
7-- 利⽤标记约束添加主键和外键
8create table if not exists t_student(
9 student_id int(10),
10 student_name varchar(20),
11 sex char(2),
12 birthday date,
13 email varchar(30),
14 classes_id int(3),
15constraint fk_classes_id foreign key (classes_id) references t_classes (classes_id),
16constraint student_id_pk primary key(student_id)
17 );
create table if not exists t_student(
student_id int(10) primary key,
student_name varchar(20),
sex char(2),mysql下载失败怎么办
birthday DATE,
email varchar(30),
classes_id2 int(3),
-- 这⾥的添加顺序是先添加主键后添加外键,会失败,提⽰语法错误
constraint student_id_pk primary key(student_id)
constraint fk_classes_id foreign key (classes_id2) references t_classes (classes_id)
);
同样是添加主键和外键,顺序颠倒后会报语法错误
数据库版本号:8.0.19
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论