当前位置:网站首页>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.
数据库连接池:【点击这里查看】
边栏推荐
- Cloud function to achieve automatic website check-in configuration details [Web function/Nodejs/cookie]
- Could you please talk about how the website is accessed?[Interview questions in the web field]
- Acwing 3208. Z字形扫描 偏移量+扩展图
- Producer and Consumer Problems in Concurrent Programming
- The difference between Mysql application log time and system time is eight hours
- DOM简述
- Qt:小的任务管理器(task)
- Since his 97, I roll but he...
- 广东对小鹏/广汽丰田开展网络安全检查
- js文字转语音播报
猜你喜欢
随机推荐
Win11怎么进行左右键对调?
【C补充】指针相关知识点收集01
用匿名函数定义函数_c语言最先执行的函数是
栈与队列的实现
【cookie 临时存储数据,WebStorage ,sessionStorage】
LeetCode简单题之最好的扑克手牌
MindSpore:【model_zoo】【resnet】尝试用THOR优化器运行时报cannot import name ‘THOR‘
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
rk3399-339 usb设备复合 总体流程
学习使用php把stdClass Object转array的方法整理
Person.class.getInterfaces() 注意使用方法
pyvista 的介绍与使用
低代码是开发的未来吗?浅谈低代码开发平台的发展现状及未来趋势
[Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
无代码平台附件上传入门教程
iMeta | 百度认证完成,搜索“iMeta”直达出版社主页和投稿链接
Get the number of cpu cores
云计算适合什么企业_当前全球云计算处于发展
HCIP 第十八天
Win11如何隐藏输入法悬浮窗?