Java学习笔记 第十一章 数据库

JAVA学习笔记第十一章

11.数据库

11.1简介

11.1.1数据库基本概念

image-20210610171649635

image-20210610171839624

11.1.2数据库类型

image-20210610172003175

image-20210610201102104

11.1.3MySQL介绍

image-20210610201214414

image-20210610201345425

11.1.4MySQL使用

image-20210610201558352

image-20210610201738601

image-20210610201830469

数据库的卸载:

image-20210610201900871

图形客户端:

image-20210610201955666

image-20210610202034863

11.2SQL语言

image-20210610202225386

image-20210610202332160

image-20210610202433092

11.2.1数据库表的操作

image-20210610232332374

image-20210610232506630

image-20210610232602455

image-20210610232638032

image-20210610234142426

image-20210610234424051

image-20210611002021591

image-20210611002056622

image-20210611002135775

11.2.2数据库表的类型

image-20210610232805371

image-20210610232902631

image-20210610232924736

11.2.3添加、修改、删除数据

添加数据:

image-20210610233140800

image-20210610233348147

修改、删除数据:

image-20210610233450117

image-20210610233620124

image-20210610233820621

image-20210611002253950

image-20210611002238659

11.2.4查询

image-20210611002449095

image-20210611002528846

image-20210611002625403

image-20210611002640366

image-20210611002716104

image-20210611002731035

image-20210611002742893

image-20210611115538515

image-20210611115604729

image-20210611115730742

image-20210611115813339

在别名中有特殊符号的时候,单引号或双引号不可以不写

image-20210611120052566

image-20210611120202315

image-20210611120322738

where语句:

image-20210611120543069

image-20210611120708090

image-20210611120811553

image-20210611120837816

image-20210611120930655

11.2.5函数

image-20210611120959328

image-20210611121109055

image-20210611121141123

单行函数:

【1】字符函数

image-20210611121309844

image-20210611121448168

image-20210611121900946

【2】数值函数

image-20210611121522167

image-20210611122033868

【3】日期与时间函数

image-20210611122207409

image-20210611122430794

image-20210611122251273

image-20210611122318551

【4】流程函数

image-20210611122516159

image-20210611122847842

image-20210611122952491

image-20210611123028197

【5】JSON函数

image-20210611122600514

【6】其他函数

image-20210611123148618

image-20210611123114140

多行函数:

image-20210611123258191

image-20210611123317131

多行函数自动忽略null值

max/min/count对所有类型有效,sum和avg只对数值类型有效

image-20210611123546046

image-20210611123535281

11.2.6分组

group by分组

image-20210611125809000

image-20210611125936869

image-20210611130042156

image-20210611130150514

11.2.7单表查询

image-20210611130301290

image-20210611130454487

image-20210611130559252

image-20210611130644318

11.2.8多表查询

image-20210611130955296

image-20210611131107907

image-20210611131222942

image-20210611131255044

image-20210611131505497

image-20210611131554773

image-20210611131700602

image-20210611131743768

外连接:

image-20210611132000421

image-20210611132129548

image-20210611132157459

image-20210611132248600

image-20210611132337694

image-20210611132420591

image-20210611132452494

outer可以省略不写

三表联查:

image-20210611132800611

自关联:

image-20210611132947445

image-20210611133058765

image-20210611133126959

92语法:

image-20210612211222164

image-20210612211325594

image-20210612211417792

11.2.9子查询

【1】子查询:一条sql语句含有多个select

image-20210612211613417

image-20210612211716940

image-20210612212218063

image-20210612212340577

image-20210612212439687

image-20210612212549746

11.3约束

11.3.1非外键约束

image-20210610234630216

image-20210610234955294

image-20210610235340443

primary key、check、unique都是表级约束,可以不用放入到列的定义中,可以在表中写,也可以在列中写。

auto_increment必须定义在主键的情况下。

创建表之后添加约束

image-20210610235751371

image-20210610235839081

image-20210610235902284

image-20210610235922999

image-20210610235945964

image-20210611000014476

image-20210611000033804

11.3.2外键约束

image-20210611000116981

image-20210611000421510

image-20210611000547828

image-20210611000652276

image-20210611000710358

这上面出现问题的原因是外键约束没加,需要添加外键约束

image-20210611000908678

注意:添加的时候必须添加班级表里面的班级,删除的时候先把所属班级的学生删除了才能删除班级

image-20210611001529639

image-20210611001722572

image-20210611001831098

image-20210611001919866

11.4数据库对象

11.4.1事务及特征

image-20210603190121610

image-20210603190147367

image-20210603190218582

image-20210603190323432

image-20210613000516444

image-20210613003229736

11.4.2事务并发问题

image-20210603190558178

读取到还没提交到数据库的数据

image-20210603190827337

事务A时间点5和7读取的数据不一致,在一个事务内两次读到的数据不一样

image-20210603191024132

image-20210603191200753

10.4.3事务的隔离级别

image-20210603191352272

image-20210613003756899

11.5视图

image-20210613004047440

视图的本质:是一个查询语句,是一个虚拟的表,查看视图就是查看对应的sql语句

image-20210613004521053

在操作视图的时候也会影响到底层的数据

or replace已存在则替换,with check option表示会校验数据,不符合条件的数据不会操作

image-20210613004711168

基于两张表创建视图:

image-20210613004949777

image-20210613005033628

image-20210613005056369

11.6存储过程

image-20210613005128673

image-20210613005320813

image-20210613005613298

image-20210613005625837

image-20210613005707845

image-20210613005812542

image-20210613005854770

posted @ 2021-06-13 01:00  wrrr  阅读(54)  评论(0编辑  收藏  举报