当前位置:网站首页>MySQL表的增删改查(基础)
MySQL表的增删改查(基础)
2022-06-27 17:53:00 【往日如风_】

1、 新增(Create)
1.1、insert 插入数据
创建数据库
指定数据库
创建表
查看表
查看表结构
插入代码:
insert into 表名 values (列的值…);
查询表

1.11、要求values()中的字段个数和表头约定的列数以及每个列的类型,要匹配

匹配
1.12、在SQL中要表示字符串,英文格式与中文格式都可以 ’ ’ , ‘’ ‘’
‘这个可以’ “这个也可以”
1.13、如果某一列是datetime(时间戳),如何匹配呢
1)通过指定格式字符串来插入一个指定时间
2)通过now()函数来插入一个 当前系统时间
首先这个表在student中
指定时间:
系统时间:
查询表(遍历?):
1.14、insert在插入过程中,可以只插入其中某一列或者某几个列,此时其他的列将采用默认设置
1)插入某列
2)插入某几个列
1.15、也可以插入中文

MySQL默认编码方式是拉丁文
配置方案在笔记中
1.16、一次插入多行


2、查找语句 select
2.1、全列查找
最基础的查找,全列查找,直接把一个表所有的列,和所有的行都查询出来
select * from 表名;
插入数据:
示例全列查找:
这里查找到的是一个临时表
数据库中的表都在硬盘中 但是这里在内存中 输出后同时释放
2.2、指定列查询
select 列名 … from 表名:
这种查询更高效
有针对性的查询
此处查询也是临时表 " 随时释放"------>打印完成就释放
2.3、指定查询字段为表达式
查询同时伴随运算操作
此时查询 语文成绩比平时多十分
也是临时表
三门成绩和
2.4、查询字段指定别名
相当于给查询的临时表,制定了新的列名
这样写容易混淆
2.5、针对查询结果去重 distinct
针对查询结果,把重复数据删除


此时无法去重
2.6、排序
针对查询结果(临时表)进行排序
select 列名… from 表名 order by 列名 asc/desc;
降序
默认升序 针对数学成绩
asc升序
排序中空值被认为最小值
排序也可以依赖表达式或者别名

针对别名排序
也可以用order by 进行多列排序
现根据第一个列排序,若第一列相同,则下一列,以此类推
2.7、select中的条件查询
select 后跟 where+具体筛选条件
select 列名 from 表明 where 条件;

where后面跟的条件和前面和列并没有关系
where字句不能使用别名


表达式里面同时具有 and 和or 那么 and 优先

曹孟德并不满足and
between------区间
数学成绩是()中任意值都可查询 —固定值查询

也可以通过or达到相同目的
通配符的使用
2.8、分页查询
有8行
我们可以任意设置一页有多少个查找结果(行)
select * from exam_result limit 一页行数;
select * from exam_result limit 3 offset 3;
select * from exam_result limit 3 offset 从第几行开始;
3、MySQL的修改操作
3.1、定义update操作
update exam_result set math = ‘80’ where name = ‘孙悟空’;

3.2、筛选操作 limit
筛选前三
增加修改操作


修改语文成绩为原来的1/2
4、删除操作 delect
delete from exam_result where id = 8;
边栏推荐
- OpenSSL client programming: SSL session failure caused by an obscure function
- 作为软件工程师,给年轻时的自己的建议(下)
- 芯动联科冲刺科创板:年营收1.7亿 北方电子院与中城创投是股东
- 工作流自动化 低代码是关键
- crontab的学习随笔
- 教你打印自己的日志 -- 如何自定义 log4j2 各组件
- Bit. Store: long bear market, stable stacking products may become the main theme
- Is it safe to buy stocks and open an account on the account opening link of the securities manager? Ask the great God for help
- 基于STM32F103ZET6库函数蜂鸣器实验
- 网上期货开户安全么?
猜你喜欢

从感知机到前馈神经网络的数学推导

工作流自动化 低代码是关键

429-二叉树(108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树、 106.从中序与后序遍历序列构造二叉树、235. 二叉搜索树的最近公共祖先)

Minmei new energy rushes to Shenzhen Stock Exchange: the annual accounts receivable exceeds 600million and the proposed fund-raising is 450million

Redis 原理 - String

Introduction to deep learning and neural networks

Keras deep learning practice (12) -- facial feature point detection

国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)

Erreur Keil de Huada Single Chip Computer La solution de Weak

实战回忆录:从Webshell开始突破边界
随机推荐
Substrate及波卡一周技术更新速递 20220425 - 20220501
NVIDIA Clara-AGX-Developer-Kit installation
Market status and development prospect forecast of the global shuttleless air jet loom industry in 2022
Introduction to deep learning and neural networks
Mathematical derivation from perceptron to feedforward neural network
一对一关系
Market status and development prospect of resorcinol derivatives for skin products in the world in 2022
Market status and development prospect forecast of global functional polyethylene glycol (PEG) industry in 2022
Bit. Store: long bear market, stable stacking products may become the main theme
作为软件工程师,给年轻时的自己的建议(下)
图扑数字孪生智慧能源一体化管控平台
券商经理的开户二维码开户买股票安全吗?有谁知道啊
Seven phases of CMS implementation
VS code 运行yarn run dev 报yarn : 无法加载文件XXX的问题
shell脚本常用命令(四)
基础数据类型和复杂数据类型
别焦虑了,这才是中国各行业的工资真相
DCC888 :Register Allocation
binder hwbinder vndbinder
redis集群系列三