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);
  • 相关阅读:
    保存宏的表-TRMAC
    问题解决]Personnel master record xxxx not found (check entry)
    检查员工号是否存在函数[RP_CHECK_PERNR]
    ◆◆0SAP IDOC 开发入门
    IDoc测试工具WE19使用教程
    ◆◆0如何从其他系统导入测试IDOC文件-WE19
    通过message type查找inbound函数-WE57,WE42,
    使用IDOC创建会计凭证[ACC_GL_POSTING01]
    ◆◆0[REUSE_ALV_GRID_DISPLAY_LVC]ALV中字段显示前导零(leading zero)
    不同网段_Pycharm访问服务器
  • 原文地址:https://www.cnblogs.com/lxyoung/p/6946611.html
Copyright © 2011-2022 走看看