数据库模块41题作业

本文介绍了学校管理系统中几个关键数据库表的设计方案,包括班级表、学生表、老师表、课程表和成绩表。每张表都详细说明了字段类型及外键约束等,为读者提供了实用的数据库设计参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

作业练习:
http://www.cnblogs.com/wupeiqi/articles/5729934.html

制表语句:

制表语句:
    班级表
               Table: class
        Create Table: CREATE TABLE `class` (
          `cid` int(11) NOT NULL AUTO_INCREMENT,
          `caption` varchar(50) DEFAULT NULL,
          PRIMARY KEY (`cid`)
        ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
        1 row in set (0.00 sec)

        
    学生表:
                       Table: student
        Create Table: CREATE TABLE `student` (
          `sid` int(11) NOT NULL AUTO_INCREMENT,
          `sname` varchar(50) DEFAULT NULL,
          `gender` char(10) DEFAULT NULL,
          `class_id` int(11) DEFAULT NULL,
          PRIMARY KEY (`sid`),
          KEY `fk_student_class` (`class_id`),
          CONSTRAINT `fk_student_class` FOREIGN KEY (`class_id`) REFERENCES `class` (`cid`)
        ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
                

    老师表:
                       Table: teacher
        Create Table: CREATE TABLE `teacher` (
          `tid` int(11) NOT NULL AUTO_INCREMENT,
          `tname` varchar(50) DEFAULT NULL,
          PRIMARY KEY (`tid`)
        ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
        1 row in set (0.00 sec)
                        
                        
    课程表:
                      Table: course
        Create Table: CREATE TABLE `course` (
          `cid` int(11) NOT NULL AUTO_INCREMENT,
          `cname` char(25) DEFAULT NULL,
          `teacher_id` int(11) DEFAULT NULL,
          PRIMARY KEY (`cid`),
          KEY `fk_course_teacher` (`teacher_id`),
          CONSTRAINT `fk_course_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`tid`)
        ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
        1 row in set (0.00 sec)

    成绩表:    
            
        create table score
             (sid int not null auto_increment primary key,
              student_id int not null,
             corse_id int not null,
             number int not null,
             unique uq_sc (student_id,corse_id),
             
             CONSTRAINT fk_sc_st FOREIGN key (student_id) REFERENCES student(sid),
             constraint fk_sc_co foreign key  (corse_id) references course(cid)
             ) engine=innodb default charset=utf8;
            
View Code

 

转载于:https://www.cnblogs.com/wanchenxi/p/8041102.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值