当前位置:网站首页>mysql 的简单运用命令
mysql 的简单运用命令
2022-07-31 05:09:00 【城南花开了^】
数据库单词
create 创建
database 数据库
drop 删除
show 展示
use 使用
delete 删除
describe 描述 desc
select 查询
varchar 字符串类型
char 字符串类型
date 日期
time 时间
datetime 时间日期语句
creata database; 库名;创建库
drop database; 库名; 删除库
show databases; 查看所有库
use 库名;使用库
desc 表名;查询表结构
desc 表名 标头;查询某一个结构
创建表基本结构
create table 表名 (
列名1 列类型
列名2 列类型
...
列名n 列类型
);修改结构
1.增加字段 add
一次增加一个字段
alter table 表名 add 字段名 字段类型;
一次增加多个字段
alter table 表名 add 字段名 字段类型 ,add 字段名 字段类型,……;
2 删除字段 drop
一次删除一个字段
alter table 表名 drop 字段名 字段类型;
一次删除多个字段
alter table 表名 drop 字段名 字段类型, drop 字段名 字段类型,……;
3 修改字段类型 modify
一次修改一个字段
alter table 表名 modify 字段名 修改字段类型;
一次修改多个字段
alter table 表名 modify 字段名 修改字段类型,modify 字段名 修改字段类型……;
4 修改字段名 change
一次修改一个字段名
alter table 表名 change 原字段名 修改后的字段名 修改后的字段类型;
一次修改多个字段名
alter table 表名 change 原字段名 修改后的字段名 修改后的字段类型,change 原字段名 修改后的字段名 修改后的字段类型……;
数据表的删除
1 删除表
drop table 表名;
2 修改表名
1)rename table 原表名 to 新表名;
2)alter table 原表名 rename to 新表名;
数据插入
1.一次添加一个
insert into 表名 (列名1,列名2,列名3) value (数据1,数据2,数据3);
2.一次添加多个
insert into 表名 (列名1,列名2,列名3) value
(数据1,数据2,数据3),
(数据1,数据2,数据3),
(数据1,数据2,数据3),
(……);查询表内容
select * from 表名;
查询单个数据
select 字段 from 表名;
查询多个数据
select 字段名1,字段名2,字段名3 from 表名;
去重查询
selest distinct 字段名 from 表名;
运算符查询
select 字段名+字段名 from 表名;
条件查询 成绩在80以上的
select 姓名,成绩 from 表名 where 成绩>80;
集合查询
1 在集合查询的范围
select * from 表名 where 字段名 in();
2 不在集合范围查询
select * from 表名 where 字段名 not in();
范围查询
select * from 表名 where 字段名 between 70 and 90;
空值查询
select 字段名 from 表名 where 成绩为空 in null;
非空值查询
select 字段名 from 表名 where 成绩 in not null;
多条件查询
select * from 表名 where 成绩>80 and age>15;
添加主键约束
alter table 表名 add primarg key (字段名);
删除自增约束/主键约束
alter table 表名 modify 字段名 字段类型;
alter table 表名 drop primarg key;
删除非空约束
alter table 表名 modify 字段名 字段类型;
删除唯一约束
alter table 表名 modify 字段名 字段类型;
alter table 表名 drop index 字段名;
删除默认约束
alter table 表名 modify 字段名 字段类型;
默认 default主键约束 primarg key
自增约束 auto_increment
外键约束
foreign key (字段名)references 表名(字段名);
删除外键
alter table 表名 drop foreign key 名字;给外键起名字 constyaint 名字
降序排列
select * from 表名 order by 字段 desc;
升序排列
select * from 表名 order by 字段 asc;修改单条记录的字段
update 表名 set 字段名='修改的名'where id=1;修改多条记录的字段
update 表名 set 字段名='修改的名' …… where id=序号;数据删除
删除一条记录
delete from 表名 where id=1;
删除多条记录
delete from 表名 where id=2 or id=3;
边栏推荐
- Doris学习笔记之监控
- sql statement - how to query data in another table based on the data in one table
- SQL语句中对时间字段进行区间查询
- Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
- Three oj questions on leetcode
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- Go中间件
- Centos7 install mysql5.7
- Minio upload file ssl certificate is not trusted
- STM32 - DMA
猜你喜欢
![<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍](/img/a4/8c75fab6a9858c5ddec25f6a8300fb.png)
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍

mysql uses on duplicate key update to update data in batches

Why use Flink and how to get started with Flink?

centos7安装mysql5.7
![[C language] Detailed explanation of operators](/img/fa/dce3da39f19b51c6d1b682128da36b.png)
[C language] Detailed explanation of operators

MySQL优化:从十几秒优化到三百毫秒

Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |

Temporal介绍

STM32——DMA

On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
随机推荐
DVWA installation tutorial (understand what you don't understand · in detail)
1. 获取数据-requests.get()
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
MySQL window function
Go中间件
.NET-9. A mess of theoretical notes (concepts, ideas)
MySQL常见面试题汇总(建议收藏!!!)
110 MySQL interview questions and answers (continuously updated)
Minesweeper game (written in c language)
MySQL优化之慢日志查询
质量小议12 -- 以测代评
对list集合进行分页,并将数据显示在页面中
The monitoring of Doris study notes
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
Temporal对比Cadence
Refinement of the four major collection frameworks: Summary of List core knowledge
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
[Detailed explanation of ORACLE Explain]
1. Get data - requests.get()
Summary of MySQL common interview questions (recommended collection!!!)