当前位置:网站首页>MySQL的基本语句(1)—增删改查
MySQL的基本语句(1)—增删改查
2022-07-27 05:24:00 【终极小腾】
前言
MySQL由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型和大型网站的开发都选择 MySQL 作为网站数据库。
所以我准备在此处记录一下比较常用的几种语句;
每一种语句只介绍一条如何操作,之后我会全面的写一个。
建表
-- 删除user表
drop table if exists user;
-- 创建user表
create table user
(
-- id 主键
id int primary key auto_increment,
-- 姓名
name varchar(20),
-- 性别
sex varchar(20),
-- 年龄
age int,
-- 邮箱
email varchar(100)
);
我们可以直接在Navicat for MySQL中点击数据库之后新建查询,复制上面代码然后运行。
运行之后我们就会得到一个初始数据表。
接下来我们去执行一些操作。
增加语句
格式:inser into 表名 (字段1,字段2,字段3……)values(值1,值2,值3……)
中间用英文逗号隔开,每一个字段都一一对应。
例如: insert into user (id,name,sex,age,email) values(null,'张三','男',21,'[email protected]')
注意,如果类型是varchar的需要用引号括起来
执行之后
删除
基本上删除语句都是根据条件进行删除的。
所以格式:delete from 表名 where 条件
例如根据id删除:delete from user where id =3

修改
基本上删除语句也是根据条件进行操作的,不过还要带入要修改的值。
所以格式:update 表名 set 数据 where 条件
例如根据id修改name: update user set name = '强哥' where id = 4 ;

查询
在这里,只演示查询全部
语句 : select * from 表名select * from user 
小结
这里只写了每个操作的一种举例,具体还有很多,等之后理解透了再写。
边栏推荐
猜你喜欢

What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!

How to avoid loopholes? Sunflower remote explains the safe use methods in different scenarios

Webodm win10 installation tutorial (personal test)

LVM与磁盘配额

Soul continues to make efforts to list its social channels in Hong Kong. Why is "soul style social" popular?

2022年全球6家最具技术实力的的智能合约审计公司盘点

FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生

Redis' idea under windows is not connected

win10 添加虚拟网卡,配置op路由

Sunflower teaches you how to prevent denial of service attacks?
随机推荐
磁盘管理与文件系统
gin-vue-admin 使用docker容器中的数据库
【12】 Understand the circuit: from telegraph to gate circuit, how can we "send messages from thousands of miles"?
Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places
Esxi virtual machine starts, and the module "monitorloop" fails to power on
Problems related to compilation and training of Darknet yolov3 and Yolo fast using CUDA environment of rtx30 Series graphics card on win10 platform
关于在Gazebo中给无人机添加相机(摄像头)之后,无人机无法起飞
Packaging of logging logs
Concept and principle of DHCP
向日葵全面科普,为你的远程控制设备及时规避漏洞
PSI|CSI和ROC|AUC和KS -备忘录
Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
Some problems about too fast s verification code
Sunflower teaches you how to prevent denial of service attacks?
Many of the world's top 500 enterprises gathered at the second digital Expo, and the digital industry curtain is about to open!
备忘录 @RestControllerAdvice与异常拦截类示例
Talk about why you need to declare the member function of a class as private
Linux安装与卸载MySql
关于过快S验证码的一些问题
A cross domain problem of golang