zoukankan      html  css  js  c++  java
  • mysql建表练习

    create table class(
    cid int primary key auto_increment,
    caption char(20) not null
    )engine=innodb;
    
    create table teacher(
    tid int primary key auto_increment,
    tname char(20) not null
    )engine=innodb;
    
    create table student(
    sid int primary key auto_increment,
    sname char(20) not null,
    gender enum('',''),
    class_id int,
    foreign key(class_id) references class(cid)
    on delete cascade
    on update cascade
    )engine=innodb;
    
    create table course(
    cid int primary key auto_increment,
    cname char(20) not null,
    teacher_id int,
    foreign key(teacher_id) references class(cid)
    on delete cascade
    on update cascade
    )engine=innodb;
    
    create table score(
    sid int primary key auto_increment,
    student_id int,
    course_id int,
    number int  unsigned not null check (number <= 100),
    foreign key(student_id) references student(sid)
    on delete cascade
    on update cascade,
    foreign key(course_id) references course(cid)
    on delete cascade
    on update cascade
    )engine=innodb;
    
    insert into class(caption) values
    ('三年二班'),
    ('一年三班'),
    ('三年一班');
    
    insert into teacher(tname) values
    ('波多'),
    ('苍空'),
    ('饭岛');
    
    insert into student(sname,gender,class_id) values
    ('钢蛋','',1),
    ('铁锤','',1),
    ('山炮','',2);
    
    insert into course(cname,teacher_id) values
    ('生物',1),
    ('体育',1),
    ('物理',1);
    
    insert into score(student_id,course_id,number) values
    (1,1,60),
    (1,2,59),
    (2,3,100);
  • 相关阅读:
    ST (Sparse Table:稀疏表)算法
    P3379 【模板】最近公共祖先(LCA)
    AT1357 n^p mod m(洛谷)
    poj2018 Best Cow Fences
    P1024 一元三次方程求解
    poj2456
    poj1064
    P2047 [NOI2007]社交网络(洛谷)
    poj1734
    洛谷P2886 [USACO07NOV]牛继电器Cow Relays
  • 原文地址:https://www.cnblogs.com/wangmo/p/7920238.html
Copyright © 2011-2022 走看看