学生选课系统

这篇博客介绍了学生选课系统中涉及的SQL基础操作,包括DDL数据定义语言和DML数据操作语言。在DDL部分,未提供具体细节。在DML部分,详细讲解了增、删、改、查四种操作。删除操作展示了如何使用delete语句删除特定行,更新操作通过update语句演示了如何修改表中数据,包括单个字段和多个字段的修改。查询操作虽然未展开,但作为SQL的重要组成部分,通常用于获取所需信息。
摘要由CSDN通过智能技术生成

一、DDL数据定义语言

-- 如果存在名为school的数据库就删除它
drop database if exists `school`;

-- 创建名为school的数据库并设置默认的字符集和排序规则
create database `school` default character set utf8mb4;

-- 切换到school数据库上下文环境
use `school`;

-- 创建学院表
create table `colleges`
(
`col_id` int unsigned not null auto_increment comment '编号',
`col_name` varchar(50) not null comment '名称',
`col_intro` varchar(500) not null default '' comment '介绍',
primary key (`col_id`)
) engine innodb auto_increment 1 comment '学院表';

-- 创建学生表
create table `students`
(
`stu_id` int unsigned not null comment '学号',
`stu_name` varchar(20) not null comment '姓名',
`stu_sex` boolean default 1 not null comment '性别',
`stu_birth` date not null comment '出生日期',
`stu_addr` varchar(255) comment '籍贯',
`col_id` int unsigned not null comment '所属学院',
primary key (`stu_id`),
constraint `fk_student_col_id` foreign key (`col_id`) references `colleges` (`col_id`)
) engine innodb comment '学生表';

-- 创建教师表
create table `teachers`
(
`tea_id` int unsigned not null comment '工号',
`tea_name` varchar(20) not null comment '姓名',
`tea_title` varchar(10) not null default '助教' comment '职称',
`col_id` int unsigned not null comment '所属学院',
primary key (`tea_id`),
constraint `fk_teacher_col_id` foreign key (`col_id`) references `colleges` (`col_id`)
) engine innodb comment '老师表';

-- 创建课程表
create table `courses`
(
`cou_id` int unsigned not null comment '编号',
`cou_name` varchar(50) not null comment '名称',
`cou_credit` int not null comment '学分',
`tea_id` int unsigned not null comment '授课老师',
primary key (`cou_id`),
constraint `fk_course_tea_id` foreign key (`tea_id`) references `teachers` (`tea_id`)
) engine innodb comment '课程表';

-- 创建选课记录表
create table `records`
(
`rec_id` bigint unsigned not null auto_increment comment '选课记录号',
`stu_id` int unsigned not null comment '学号',
`cou_id` int unsigned not null comment '课程编号',
`sel_date` date not null comment '选课日期',
`score` decimal(4,1) comment '考试成绩',
primary key (`rec_id`),
constraint `fk_record_stu_id` foreign key (`stu_id`) references `students` (`stu_id`),
constraint `fk_record_cou_id` foreign key (`cou_id`) references `courses` (`cou_id`),
constraint `uk_record_stu_cou` unique (`stu_id`, `cou_id`)
) engine innodb auto_increment 1 comment '选课记录表';

二、DML数据操作语言

1.增

use `school`;

-- 插入学院数据
insert into `colleges` 
    (`col_name`, `col_intro`) 
values 
    ('计算机学院', '计算机学院1958年设立计算机专业,1981年建立计算机科学系,1998年设立计算机学院,2005年5月,为了进一步整合教学和科研资源,学校决定,计算机学院和软件学院行政班子合并统一运作、实行教学和学生管理独立运行的模式。 学院下设三个系:计算机科学与技术系、物联网工程系、计算金融系;两个研究所:图象图形研究所、网络空间安全研究院(2015年成立);三个教学实验中心:计算机基础教学实验中心、IBM技术中心和计算机专业实验中心。'),
    ('外国语学院', '外国语学院设有7个教学单位,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值