我的编程空间,编程开发者的网络收藏夹
学习永远不晚

50个SQL语句(MySQL版) 建表 插入数据

短信预约 信息系统项目管理师 报名、考试、查分时间动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

50个SQL语句(MySQL版) 建表 插入数据

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("1000","张无忌",18,""),
("1001","周芷若",19,""),
("1002","杨过",19,""),
("1003","赵敏",18,""),
("1004","小龙女",17,""),
("1005","张三丰",18,""),
("1006","令狐冲",19,""),
("1007","任盈盈",20,""),
("1008","岳灵珊",19,""),
("1009","韦小宝",18,""),
("1010","康敏",17,""),
("1011","萧峰",19,""),
("1012","黄蓉",18,""),
("1013","郭靖",19,""),
("1014","周伯通",19,""),
("1015","瑛姑",20,""),
("1016","李秋水",21,""),
("1017","黄药师",18,""),
("1018","李莫愁",18,""),
("1019","冯默风",17,""),
("1020","王重阳",17,""),
("1021","郭襄",18,"");

insert into teacher value("001","姚明"),
("002","叶平"),
("003","叶开"),
("004","孟星魂"),
("005","独孤求败"),
("006","裘千仞"),
("007","裘千尺"),
("008","赵志敬"),
("009","阿紫"),
("010","郭芙蓉"),
("011","佟湘玉"),
("012","白展堂"),
("013","吕轻侯"),
("014","李大嘴"),
("015","花无缺"),
("016","金不换"),
("017","乔丹");

insert into course value("001","企业管理","002"),
("002","马克思","008"),
("003","UML","006"),
("004","数据库","007"),
("005","逻辑电路","006"),
("006","英语","003"),
("007","电子电路","005"),
("008","思想概论","004"),
("009","西方哲学史","012"),
("010","线性代数","017"),
("011","计算机基础","013"),
("012","AUTO CAD制图","015"),
("013","平面设计","011"),
("014","Flash动漫","001"),
("015","Java开发","009"),
("016","C#基础","002"),
("017","Oracl数据库原理","010");

insert into sc value("1001","003",90),
("1001","002",87),
("1001","001",96),
("1001","010",85),
("1002","003",70),
("1002","002",87),
("1002","001",42),
("1002","010",65),
("1003","006",78),
("1003","003",70),
("1003","005",70),
("1003","001",32),
("1003","010",85),
("1003","011",21),
("1004","007",90),
("1004","002",87),
("1005","001",23),
("1006","015",85),
("1006","006",46),
("1006","003",59),
("1006","004",70),
("1006","001",99),
("1007","011",85),
("1007","006",84),
("1007","003",72),
("1007","002",87),
("1008","001",94),
("1008","012",85),
("1008","006",32),
("1009","003",90),
("1009","002",82),
("1009","001",96),
("1009","010",82),
("1009","008",92),
("1010","003",90),
("1010","002",87),
("1010","001",96),
("1011","009",24),
("1011","009",25),
("1012","003",30),
("1013","002",37),
("1013","001",16),
("1013","007",55),
("1013","006",42),
("1013","012",34),
("1000","004",16),
("1002","004",55),
("1004","004",42),
("1008","004",34),
("1013","016",86),
("1013","016",44),
("1000","014",75),
("1002","016",100),
("1004","001",83),
("1008","013",97);

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

50个SQL语句(MySQL版) 建表 插入数据

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

50个SQL语句(MySQL版) 建表 插入数据

本学期正在学习数据库,前段时间老师让我们做一下50个经典SQL语句,当时做的比较快,有一些也是百度的,自我感觉理解的不是很透彻。所以从本篇随笔开始,我将进行50个经典SQL语句的复盘,加深理解。答案仅供参考,不一定完全正确,若发现错误或有更好的,欢迎评论,互相
50个SQL语句(MySQL版) 建表 插入数据
2018-05-15

50个SQL语句(MySQL版) 问题二

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题二
2016-03-02

50个SQL语句(MySQL版) 问题五

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题五
2014-12-11

50个SQL语句(MySQL版) 问题一

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题一
2017-05-02

50个SQL语句(MySQL版) 问题四

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题四
2019-08-01

50个SQL语句(MySQL版) 问题七

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题七
2021-04-29

50个SQL语句(MySQL版) 问题三

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题三
2021-10-10

50个SQL语句(MySQL版) 问题八

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题八
2014-05-09

50个SQL语句(MySQL版) 问题六

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题六
2015-05-11

50个SQL语句(MySQL版) 问题十

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十
2014-10-06

50个SQL语句(MySQL版) 问题九

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题九
2017-08-19

【sql】MySQL——插入语句(联表插入)

今天用mysql插入联表数据遇见了一些问题,于是整理一下mysql插入语句。 插入语句 语法 方式一INSERT INTO表名(列名,...)VALUES(值1,...);方式二INSERT INTO表名SET列名=值,列名=值,...
2023-08-16

50个SQL语句(MySQL版) 问题十三

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十三
2019-09-16

50个SQL语句(MySQL版) 问题十七

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十七
2015-11-21

50个SQL语句(MySQL版) 问题十八

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十八
2015-04-02

50个SQL语句(MySQL版) 问题十一

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十一
2021-10-15

50个SQL语句(MySQL版) 问题十四

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十四
2021-08-29

50个SQL语句(MySQL版) 问题十六

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十六
2021-12-15

50个SQL语句(MySQL版) 问题十九

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十九
2022-04-03

50个SQL语句(MySQL版) 问题十二

--------------------------表结构--------------------------student(StuId,StuName,StuAge,StuSex) 学生表teacher(TId,Tname) 教师表course(CId,Cn
50个SQL语句(MySQL版) 问题十二
2019-10-23

编程热搜

目录