当前位置:网站首页>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.
数据库连接池:【点击这里查看】
边栏推荐
猜你喜欢
随机推荐
什么是元宇宙?
Win10电脑经常发出叮咚声音怎么关闭
bash shell数组详解
leetcode动态规划系列(求路径篇)
js文字转语音播报
物体颜色的来源
云计算适合什么企业_当前全球云计算处于发展
请问同一个oracle cdc表,如果flink job重新提交,是会全量读取一遍源数据还是增量呢?
双指针方法
渗透——信息收集
蜜芽CEO刘楠:垂直电商黄金时代已落幕 坚定转型品牌之路
LeetCode中等题之旋转图像
[Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
关于ARM2440中断源个数的一点想法[通俗易懂]
[Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
无代码平台多行文字入门教程
Shell编程的条件语句
LeetCode 6. Z 字形变换 找规律
Win11怎么进行左右键对调?
各位大佬,请问mysql数据的cdc,能指定存量数据同步的zone为utc 吗









