当前位置:网站首页>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;
边栏推荐
- 限流的原理
- Sql解析转换之JSqlParse完整介绍
- MySQL transaction (transaction) (this is enough..)
- 关于superset集成到自己的项目中
- ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
- Minio upload file ssl certificate is not trusted
- MYSQL一站式学习,看完即学完
- Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
- 【一起学Rust】Rust的Hello Rust详细解析
- MySQL forgot password
猜你喜欢

面试官,不要再问我三次握手和四次挥手

Unity resources management series: Unity framework how to resource management

Linux系统安装mysql(rpm方式安装)

Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode

SQL row-column conversion

分布式事务处理方案大 PK!

Blockbuster | foundation for platinum, gold, silver gave nameboards donors

ERROR 1819 (HY000) Your password does not satisfy the current policy requirements

CentOS7 —— yum安装mysql

TOGAF之架构标准规范(一)
随机推荐
.NET-9. A mess of theoretical notes (concepts, ideas)
pytorch中的一维、二维、三维卷积操作
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Apache DButils使用注意事项--with modifiers “public“
Minesweeper game (written in c language)
A complete introduction to JSqlParse of Sql parsing and conversion
如何将项目部署到服务器上(全套教程)
[Detailed explanation of ORACLE Explain]
MySQL(更新中)
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
【一起学Rust】Rust学习前准备——注释和格式化输出
12个MySQL慢查询的原因分析
mysql uses on duplicate key update to update data in batches
精解四大集合框架:List 核心知识总结
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
Anaconda配置环境指令
Workflow番外篇
MySQL优化之慢日志查询
CentOS7 install MySQL graphic detailed tutorial
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.