当前位置:网站首页>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.
数据库连接池:【点击这里查看】
边栏推荐
- XCTF-reverse-signin
- 学习在微信小程序中判断url的文件后缀格式
- 用匿名函数定义函数_c语言最先执行的函数是
- SVG 的 path 属性绘制图形
- 双重for循环案例以及while循环和do while循环案例
- 数据使用要谨慎——不良数据带来严重后果
- Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]
- Could you please talk about how the website is accessed?[Interview questions in the web field]
- 数据万象内容审核 — 共建安全互联网,专项开展“清朗”直播整治行动
- Inheritance and the static keyword
猜你喜欢
随机推荐
请问下Flink SQL如何写hologres分区表?我想要每天一个分区
How Oracle for current library or certain library data on the same server number?
JDBC知识点
gom登录器配置教程_谷歌浏览器如何使用谷歌搜索引擎
[Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
有了这篇 Kubernetes 的介绍,它的原理秒懂!
leetcode经典例题——56.合并区间
数据万象内容审核 — 共建安全互联网,专项开展“清朗”直播整治行动
多了&lt;audio controls=
I am 37 this year, and I was rushed by a big factory to...
无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
学习使用php把stdClass Object转array的方法整理
IDEA 自动导入的配置(Auto import)
云计算适合什么企业_当前全球云计算处于发展
sqlilabs less-38~39
学习在php中分析switch与ifelse的执行效率
二叉树的基础练习
Shell编程的条件语句
移动端 开源低代码工具 beeware 和 kivy
Win11怎么进行左右键对调?









