当前位置:网站首页>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;
边栏推荐
- 对list集合进行分页,并将数据显示在页面中
- MySQL开窗函数
- centos7安装mysql5.7步骤(图解版)
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- Flink sink redis 写入Redis
- Input length must be multiple of 8 when decrypting with padded cipher
- mysql存储过程
- DVWA之SQL注入
- [Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
- Pytorch教程Introduction中的神经网络实现示例
猜你喜欢

为什么要用Flink,怎么入门使用Flink?

12个MySQL慢查询的原因分析

Centos7 install mysql5.7 steps (graphical version)

STM32 - DMA

mysql5.7.35安装配置教程【超级详细安装教程】

matlab abel变换图片处理

Anaconda配置环境指令

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

Minesweeper game (written in c language)
![Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]](/img/7c/c9ab32bbf43b933e5f84f0d142f7bd.jpg)
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
随机推荐
[mysql improves query efficiency] Mysql database query is slow to solve the problem
Temporal对比Cadence
【ORACLE Explain 详解】
MYSQL下载及安装完整教程
12个MySQL慢查询的原因分析
Blockbuster | foundation for platinum, gold, silver gave nameboards donors
精解四大集合框架:List 核心知识总结
ABC D - Distinct Trio(k元组的个数
numpy和pytorch中的元素拼接操作:stack,concatenat,cat
Go中间件
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
MySQL window function
Mysql application cannot find my.ini file after installation
MySQL忘记密码怎么办
mysql5.7.35安装配置教程【超级详细安装教程】
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
MySQL transaction (transaction) (this is enough..)
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
CentOS7 - yum install mysql
MySQL优化:从十几秒优化到三百毫秒