创建几张练习表

 

1、自行创建测试数据

创建学生表mysql> create table student(sid int not null primary key auto_increment, sname varchar(20), gender enum('',''), class_id int );

插入数据   mysql> insert into student values(1,'钢蛋','',1),(2,'铁蛋','',1),(3,'山炮','',2);

创建班级表 mysql>create table class(cid int not null primary key, caption  varchar(20));

插入数据   mysql> insert into class values(1,'三年级二班'),(2,'一年级三班'),(3,'三年级一班');

设置外键   mysql> alter table student add foreign key (class_id) references class (cid);

创建教师表 mysql> create table teacher(tid int not null, tname varchar(20));

插入数据   mysql> insert into teacher values(1,'波多'),(2,'苍空'),(3,'饭岛');

创建课程表 mysql> create table course(cid int, cname varchar(10), tearch_id int);

插入数据   mysql> insert into course values(1,'生物',1),(2,'体育',1),(3,'物理',2);

设置主外键 mysql> alter table course add foreign key (tearch_id) references teacher (tid);

创建分数表 mysql> create table score(sid int, student_id int, corse_id int,number int);

插入数据   mysql> insert into score values(1,1,1,60),(2,1,2,59),(3,2,2,100);

设置主键   mysql> alter table score add primary key (sid,corse_id);

 

posted @ 2021-06-24 22:05  vip网管  阅读(62)  评论(0)    收藏  举报