当前位置:网站首页>第6天总结&数据库作业
第6天总结&数据库作业
2022-07-26 08:41:00 【xbxbgk】
1.数据库的分类
关系型:mysql,oracle,sqllite(移动端自带的,django默认),sql server
非关系型:redis,mongoDB
2.mysql安装
保证:安装之前检查电脑是否安装过,卸载 mysql5.5版本,django使用5.5以上
数据库是用于存储数据
库/表 库类似目录 表类似目录中excle
3.基本知识点
sql语句
专门用于操作库和表的 重点
sql语句的分类
数据库查询语言(DQL) select
数据库操作语言(DML) delete update insert
数据库定义语言(DDL) 创建、删除、修改表的结构 create、drop、alter
字段类型
整数:int/bigint
小数:float/double
字符串:char/varchar
时间:date/time/datetime
字段的约束
null 可以为空
not null 不能为空
default 默认值
primary key 主键
auto_increment 自增
charset 设置字符集
4.DDL数据库定义语言
创建库
create database 库名 CHARSET=utf8;
删除库
DROP DATABASE 库名;
查询创建的库的语句
show create DATABASE 库名;
使用库
use 库名
创建表
create table 表名(字段 类型 长度,字段 类型 长度)
删除表
drop table 表名
查询创建表的语句
show create table 表名;
查询表的结构
desc 表名
修改表结构
新增:alter table 表名 add 字段名 类型 长度;
修改:alter table 表名 MODIFY COLUMN 字段名 类型 长度;
删除: alter table 表名 drop 字段名;
5.DML数据库操作语言
新增
insert into 表名 value (值,值,值,值), (值,值,值,值)
修改
UPDATE 表名 set 字段=新值 where 条件 修改一个字段的数据
UPDATE 表名 set 字段=新值,字段=新值 where 条件 修改二个字段的数据
删除
delete from 表名 where 条件 删除指定数据
delete from 表名 删除全部数据
6.DQL数据库查询语言
查询全部的数据:select * from 表名;
查询指定字段的数据:select 字段名,字段名 from 表名;
比较运算符: > >= < <=
select * from 表名 where 字段 >值;
逻辑运算符:and or not
SELECT * from student where sex='女' and score>92
SELECT * from student where sex='女' or score>92
SELECT * from student where sex='男'
SELECT * from student where not sex='女'
关键字--模糊查询
select * from 表名 where 字段 like '%模糊数据%'
eg:%:匹配全部数据 _:代表匹配一个字符
范围查询 80~95
在...之间 在....里
SELECT * from student where score BETWEEN 80 and 95;
SELECT * from student where id in(1,3,5,7)
排序
select * from 表名 order by 字段 desc(倒序),字段 desc(倒序)
分组
函数:count() 查询数量 sum()和 max()取最大 min()取最小 avg()平均数
select count(*) from 表名 group by 字段 having 条件
eg:having 类似where 但是一般where后面不能和函数一块使用,having可以经常和group by一块使用
分页
limit 起始索引位置,显示的条数
SELECT * from student LIMIT 0,3
作业1
作业2
作业6
作业7
增删改查
边栏推荐
- Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
- 23.5 event listeners of application events and listeners
- Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
- 【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
- Registration of finite element learning knowledge points
- 23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
- Oracle 19C OCP 1z0-082 certification examination question bank 1
- Memory management - dynamic partition allocation simulation
- 基于C语言的哈夫曼转化软件
- Redis advanced
猜你喜欢
Pan micro e-cology8 foreground SQL injection POC
Study notes of automatic control principle --- stability analysis of control system
C#入门系列(三十一) -- 运算符重载
Regular expression: judge whether it conforms to USD format
Leetcode and query question summary
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects
The lessons of 2000. Web3 = the third industrial revolution?
node-v下载与应用、ES6模块导入与导出
Mysql/mariadb (Galera multi master mode) cluster construction
随机推荐
day06 作业--技能题6
Flutter WebView jitter
[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
Study notes of automatic control principle -- dynamic model of feedback control system
23.6 23.7 web environment web environment variable reading
Mycat2 deploy master-slave MariaDB
Study notes of automatic control principle --- stability analysis of control system
Using the primitive root of module m to judge and solve
Cadence (x) wiring skills and precautions
Xshell batch send command to multiple sessions
JDBC数据库连接池(Druid技术)
[recommended collection] summary of MySQL 30000 word essence - partitions, tables, databases and master-slave replication (V)
Does flinkcdc now support sqlserver instance name connection?
Dear teachers, how can sqlserver get DDL in flinkcdc?
Excel delete blank lines
Huffman transformation software based on C language
Flutter WebView three fingers rush or freeze the screen
Leetcode and query question summary
2000年的教训。web3是否=第三次工业革命?
My meeting of OA project (query)