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 ...
随机推荐
- QT入门指导
罗列一些QT学习资料 1. http://www.qter.org/ 包含很多教程,包括著名的<学习之路>系列. 2. http://www.qtcn.org/bbs/index-htm- ...
- wmic 内网使用
先决条件: 1.远程服务器启动Windows Management Instrumentation服务,开放TCP135端口,防火墙放开对此端口的流量(默认放开): 2.远程服务器的本地安全策略的“网 ...
- C. Game with Chips(陷阱暴力题)
\(为什么说这是个陷阱呢??\) \(因为不管你脑洞多大,数学多好,都发现会束手无策\) \(每移动一次不知道往哪个方向,不知道先访问哪个点,同时要记录所有点的坐标,记录每个点是否访问过目标点.... ...
- (二)Redis在Mac下的安装与SpringBoot中的配置
1 下载Redis 官网下载,下载 stable 版本,稳定版本. 2 本地安装 解压:tar zxvf redis-6.0.1.tar.gz 移动到: sudo mv redis-6.0.1 /us ...
- Spring杂谈 | Spring中的AutowireCandidateResolver
接口定义 用于推断一个特定的beanDefinition是否能作为指定依赖的候选者的策略接口 public interface AutowireCandidateResolver { // 默认情况下 ...
- LeetCode--Array--Two sum (Easy)
1.Two sum (Easy)# Given an array of integers, return indices of the two numbers such that they add u ...
- Pytest 单元测试框架
1.pytest 是 python 的第三方单元测试框架,比自带 unittest 更简洁和高效 2.安装 pytest pip install pytest 3.验证 pytest 是否安装成功 p ...
- JS字符串截取 “指定字符” 前面和后面的内容!
JS字符串截取 “指定字符” 前面和后面的内容! var string= "07/12" var before = string.split('/')[0] var after = ...
- [codeforces-543B]bfs求最短路
题意:给一个边长为1的无向图,求删去最多的边使得从a到b距离<=f,从c到d距离<=g,a,b,c,d,f,g都是给定的,求最多删去的边数. 思路:反过来思考,用最少的边构造两条从a到b, ...
- bash初始化小建议
bash有一些很好用但已经常被人忽略的小技巧,谨以此文记录下…… 1. 给history命令加上时间 history的命令很好用,他可以记录我们之前做了哪些操作,有了这些记录,我们可以很快捷的重复执行 ...