MySql学习笔记

MySql学习视频地址:

https://www.bilibili.com/video/BV1fx411X7BD?p=55&spm_id_from=pageDriver

 

P55:外键约束

drop table if exists t_student;
drop table if exists t_class;


create table t_class(
	cno int primary key,
	cname varchar(255)
);
create table t_student (
	sno int primary key,
	sname varchar(255),
	classno int,
	foreign key(classno) references t_class(cno)
);
insert into t_class values(101,"xxxxxxxxxxx");
insert into t_class values(102,"yyyyyyyyy");

insert into t_student values(1,"zs01",101);
insert into t_student values(2,"zs02",101);
insert into t_student values(3,"zs03",102);
insert into t_student values(4,"zs04",102);
insert into t_student values(5,"zs05",102);

select * from t_class;
select * from t_student;

  

 

posted @ 2021-10-15 09:26  生如逆旅,一苇以航  阅读(23)  评论(0编辑  收藏  举报