50个SQL语句(MySQL版) 建表 插入数据
本学期正在学习数据库,前段时间老师让我们做一下50个经典SQL语句,当时做的比较快,有一些也是百度的,自我感觉理解的不是很透彻。
所以从本篇随笔开始,我将进行50个经典SQL语句的复盘,加深理解。
答案仅供参考,不一定完全正确,若发现错误或有更好的,欢迎评论,互相交流,一起成长!!!
--------------------------表结构--------------------------
student(StuId,StuName,StuAge,StuSex) 学生表
teacher(TId,Tname) 教师表
course(CId,Cname,C_TId) 课程表
sc(SId,S_CId,Score) 成绩表
----------------------------------------------------------
建表:
create database MySchool character set "utf8mb4";
use MySchool;
create table student
(
StuId varchar(5) primary key,
StuName varchar(10) not null,
StuAge int,
StuSex char(2) not null
);
create table teacher
(
TId varchar(3) primary key,
Tname varchar(10) not null
);
create table course
(
CId varchar(3) primary key,
Cname varchar(20) not null,
C_TId varchar(3) not null,
FOREIGN KEY (C_TId) REFERENCES teacher(TId)
);
create table sc
(
SId varchar(5) not null,
FOREIGN KEY (SId) REFERENCES student(StuId),
S_CId varchar(3) not null,
FOREIGN KEY (S_CId) REFERENCES course(CId),
Score float
);
插入数据:
insert into student value('','张无忌',18,'男'),
('','周芷若',19,'女'),
('','杨过',19,'男'),
('','赵敏',18,'女'),
('','小龙女',17,'女'),
('','张三丰',18,'男'),
('','令狐冲',19,'男'),
('','任盈盈',20,'女'),
('','岳灵珊',19,'女'),
('','韦小宝',18,'男'),
('','康敏',17,'女'),
('','萧峰',19,'男'),
('','黄蓉',18,'女'),
('','郭靖',19,'男'),
('','周伯通',19,'男'),
('','瑛姑',20,'女'),
('','李秋水',21,'女'),
('','黄药师',18,'男'),
('','李莫愁',18,'女'),
('','冯默风',17,'男'),
('','王重阳',17,'男'),
('','郭襄',18,'女');
insert into teacher value('','姚明'),
('','叶平'),
('','叶开'),
('','孟星魂'),
('','独孤求败'),
('','裘千仞'),
('','裘千尺'),
('','赵志敬'),
('','阿紫'),
('','郭芙蓉'),
('','佟湘玉'),
('','白展堂'),
('','吕轻侯'),
('','李大嘴'),
('','花无缺'),
('','金不换'),
('','乔丹');
insert into course value('','企业管理',''),
('','马克思',''),
('','UML',''),
('','数据库',''),
('','逻辑电路',''),
('','英语',''),
('','电子电路',''),
('','思想概论',''),
('','西方哲学史',''),
('','线性代数',''),
('','计算机基础',''),
('','AUTO CAD制图',''),
('','平面设计',''),
('','Flash动漫',''),
('','Java开发',''),
('','C#基础',''),
('','Oracl数据库原理','');
insert into sc value('','',90),
('','',87),
('','',96),
('','',85),
('','',70),
('','',87),
('','',42),
('','',65),
('','',78),
('','',70),
('','',70),
('','',32),
('','',85),
('','',21),
('','',90),
('','',87),
('','',23),
('','',85),
('','',46),
('','',59),
('','',70),
('','',99),
('','',85),
('','',84),
('','',72),
('','',87),
('','',94),
('','',85),
('','',32),
('','',90),
('','',82),
('','',96),
('','',82),
('','',92),
('','',90),
('','',87),
('','',96),
('','',24),
('','',25),
('','',30),
('','',37),
('','',16),
('','',55),
('','',42),
('','',34),
('','',16),
('','',55),
('','',42),
('','',34),
('','',86),
('','',44),
('','',75),
('','',100),
('','',83),
('','',97);
50个SQL语句(MySQL版) 建表 插入数据的更多相关文章
- 50个SQL语句(MySQL版) 问题十四
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题十三
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题十二
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题十一
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题十
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题九
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题八
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题七
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 50个SQL语句(MySQL版) 问题六
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
随机推荐
- ocelot jwt 进行统一验证
前一个帖子发了有关jwt 验证api的内容,这一次将jwt集成到ocelot网关中. ocelot集成jwt有一个很不错的nuget包,ocelot.jwtauthorize ,但是这个包似乎支持n ...
- 设计模式之GOF23访问者模式
访问者模式Visitor 模式动机:对于存储在一个集合中的对象,他们可能具有不同的类型(即使有一个公共的接口),对于该集合中的对象,可以接受一类称为访问者的对象来访问,不同访问者的访问方式也不同 定义 ...
- [hdu5439 Aggregated Counting]公式化简,预处理
题意:按下列规则生成一组序列,令f(n)为n这个数在序列中出现的最后一个位置,求f(f(n))的值. 1. First, write down 1, 2 on a paper.2. The 2nd n ...
- javaweb学习之路(1)request
1.本次练习写一个简单的注册页面 准备工作:首先搭建好服务器tomcat环境,使用的编译软件是eclipse 2.在eclipse中创建一个web工程 3.在webContent文件夹下创建一个reg ...
- java -> StringBuffer与StringBuilder类
字符串缓冲区 StringBuffer类 在学习String类时,API中说字符串缓冲区支持可变的字符串,什么是字符串缓冲区呢?接下来我们来研究下字符串缓冲区. 查阅StringBuffer的API, ...
- GitHub 热点速览 Vol.20:VSCode 插件全家桶新增画图小能手
作者:HelloGitHub-小鱼干 摘要:后浪,这个五月热词用来概括 GitHub 本周热点无疑是最佳词汇.Deno 这个 Node.js 作者制造出来的后浪,掀起了 GitHub Trending ...
- Postman学习之Authorization
前言:本章将学习Postman当中的授权——Authorization 一.简介 Authorization顾名思义就是授权的意思,那是给谁授权呢?又有多少种授权的方式呢?Authorization是 ...
- 解决 Loaded plugins: fastestmirror
其大概意思是fastestmirror不能使用,fastestmirror是yum的一个加速插件,具体我也没有仔细了解过,可能是系统不支持或者缺少组建导致的.处理办法就是禁用这个插件,方法如下:roo ...
- python 之模块引入
模块引入: 1.同级引入 如 ac_first.py 引入ac_second.py:只需直接 import ac_second 即可 这种情况 不论是 python ac\ac_first.py 还是 ...
- 记一条sql语句优化
傻瓜级的.此sql语句存在于分销王系统中. 查阅slow log ,时间设置1s 发现很多 SELECT r.*, goods_id, bn, name FROM sdb_goods_rate r, ...