当前位置:网站首页>MySQL core SQL: SQL structured query statements, library, table operation, CRUD
MySQL core SQL: SQL structured query statements, library, table operation, CRUD
2022-08-04 10:01:00 【_Sauron】
结构化查询语句SQL
SQL是结构化查询语言(Structure Query Language),它是关系型数据库的通用语言.
SQL主要可以划分为以下 3 个类别:
DDL(Data Definition Languages)语句
数据定义语言,这些语句定义了不同的数据库、表、列、索引等数据库对象的定义.常用的语句关键字主要包括 create、drop、alter等.
DML(Data Manipulation Language)语句
数据操纵语句,用于添加、删除、更新和查询数据库记录,并检查数据完整性,常用的语句关键字主要包括 insert、delete、update 和select 等.
DCL(Data Control Language)语句
数据控制语句,用于控制不同的许可和访问级别的语句.这些语句定义了数据库、表、字段、用户的访问权限和安全级别.主要的语句关键字包括 grant、revoke 等.
库操作
首先查看mysql服务是否工作正常(默认在3306端口)

输入密码进入MySQL

查询数据库
show databases;

创建数据库
create database TestDB;
删除数据库
drop database TestDB;
选择数据库
use TestDB;
表操作
查看表
show tables;

创建表
create table user(id int unsigned primary key not null auto_increment,
name varchar(50) not null,
age tinyint not null,
sex enum('M','W') not null)engine=INNODB default charset=utf8;

查看表结构
desc user;

查看建表SQL
show create table user\G
show create table user;


删除表
drop table user;

CURD操作
insert 增加
insert into user(name, age, sex) values(‘zhang san’, 20, ‘M’);
注意,这个insertIt is based on the fields of the table created above,为什么没写ID,因为IDis an auto-increment key.

update 修改
update user set age = age + 1;

delete 删除
delete from user where id = 1;

select 查询
select* from user;
select id,name,age,sex from user;
select id,name from user;
select id,name,age,sex from user where sex=‘M’ and age>=20 and age<=25;
select id,name,age,sex from user where sex=‘M’ and age between 20 and
25;
select id,name,age,sex from user where sex=‘W’ or age>=22;
It can be used with operators to achieve different query effects
去重 distinct
For example, to know what is in the tableuserWhat age groups are they:
select distinct age from user;

问题
1.面试题:Tables with auto-increment keys,删除其中一条数据,After adding data,Whether the auto-increment key is deleted before or filled later?
In fact, it continues to increase itself.

2.The following two ways to increase,请问他们有什么区别?

实际上,客户端与MySQL Server需要先进行TCP三次握手,Then the first repetitioninsertThis will lead to the following three steps15次,而第二种方式,The following three steps are performed only once.

有需要,You can learn about database connection pooling,Found through performance testing,省略大量TCP三次握手,The efficiency improvement is still possible.
数据库连接池:【点击这里查看】
边栏推荐
- MindSpore:model.train中的dataset_sink_mode该如何理解?
- leetcode二叉树系列(二叉搜索树篇)
- 在测试集上训练,还能中CVPR?这篇IEEE批判论文是否合理?
- [Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
- usb设备复合g_webcam摄像头码流传输功能以及g_serial串口功能
- 栈与队列的实现
- MindSpore:Batchnorm only support nchw input!
- MindSpore:mirrorpad算子速度过慢的问题
- gom登录器配置教程_谷歌浏览器如何使用谷歌搜索引擎
- LVS+Keepalived群集部署
猜你喜欢

DOM简述

leetcode经典例题——56.合并区间

双指针方法

HCIP 交换实验

2022-08-03 第六小组 瞒春 学习笔记

罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍

无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输

v-model原理,在“radio”、“checkbox”、“select”、修饰符
![Detailed Explanation of Addresses Delivered by DHCP on Routing/Layer 3 Switches [Huawei eNSP]](/img/9c/b4ebe608cf639b8348adc1f1cc71c8.png)
Detailed Explanation of Addresses Delivered by DHCP on Routing/Layer 3 Switches [Huawei eNSP]
![Could you please talk about how the website is accessed?[Interview questions in the web field]](/img/06/5ecc617edc4131c31f71d5e019a64c.png)
Could you please talk about how the website is accessed?[Interview questions in the web field]
随机推荐
Interview at 14:00 in the afternoon, I came out at 14:08 with my head down, asking too much...
leetcode每天5题-Day06
Person.class.getInterfaces() 注意使用方法
MindSpore:MindSpore GPU版本安装问题
Producer and Consumer Problems in Concurrent Programming
黑马瑞吉外卖之员工账号的禁用和启用以及编辑修改
LeetCode中等题之旋转图像
二叉树与堆
渗透——信息收集
Multimedia and Internet of Things technology make the version "live" 129 vinyl records "Centennial Voice"
参数优化文档介绍
无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
关于ARM2440中断源个数的一点想法[通俗易懂]
LeetCode581+621+207
Qt:小的任务管理器(task)
暴力破解ssh/rdp/mysql/smb服务
无代码平台附件上传入门教程
Libtomcrypt AES 加密及解密
MindSpore:Ascend运行出现问题
微信小程序自定义组件-城市选择「建议收藏」