zoukankan      html  css  js  c++  java
  • Day.1建表小作业

    Mysql练习题博客地址:http://www.cnblogs.com/wupeiqi/articles/5729934.html

    代码如下:

    班级表class:

    create table class(
        cid int not null auto_increment primary key,
        caption char(10))engine=innodb default charset=utf8;
    
    insert into class (caption) values ('三年二班'),('一年三班'),('三年一班');

    教师表teacher:

    create table teacher(
        tid int not null auto_increment primary key,
        tname char(10))engine=innodb default charset=utf8;
    
    insert into teacher (tname) values ('egon'),('alex'),('wusir');

    学生表student:

    create table student(
        sid int not null auto_increment primary key,
        sname char(10),gender enum('',''),
        class_id int not null,
        constraint fk_sc foreign key (class_id) references     
        class(cid))engine=innodb default charset=utf8;
    
    insert into student (sname,gender,class_id) values('钢蛋','',1),('铁锤','',1),('山炮','',2);

    课程表course:

    create table course(
        cid int not null primary key auto_increment,
        cname char(10),teacher_id int not null,
        constraint fk_ct foreign key (teacher_id) references     
        teacher(tid))engine=innodb default charset=utf8;
    
    insert into course (cname,teacher_id) values('生物',1),('体育',1),('物理',2);

    分数表score:

    create table score(
        sid int not null auto_increment primary key,
        student_id int not null,
        course_id int not null,
        number int not null,
        constraint fk_ss foreign key (student_id) references student(sid),
        constraint fk_scadd foreign key (course_id) references 
        course(cid))engine=innodb default charset=utf8;
    
    insert into score(student_id,course_id,number) values(1,1,60),(1,2,59),(2,2,100);

    为分数表的student_id与course_id绑定为唯一索引值(也可以在建表时在constraint语句上面添加unique语句):

    alter table score add unique uni_score(student_id,course_id);
  • 相关阅读:
    Redis-高级教程-Java 使用
    Redis-高级教程-分区
    Redis-高级教程-管道技术
    Redis-高级教程-客户端连接
    Redis-高级教程-性能测试
    Redis-高级教程-安全
    Redis-高级教程-数据备份与恢复
    Redis-命令-Stream
    NG-ZORRO + Angular11增加自定义全局样式,不影响其他页面全局样式,仅作用于当前页面
    VUE上传表格文件发送后端,后端解析以及上传文件,前端进行解析的实现方法
  • 原文地址:https://www.cnblogs.com/lxyoung/p/6946611.html
Copyright © 2011-2022 走看看