当前位置:网站首页>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;
边栏推荐
- ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
- Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
- 目标检测学习笔记
- mysql使用on duplicate key update批量更新数据
- MySQL optimization slow log query
- 再见了繁琐的Excel,掌握数据分析处理技术就靠它了
- Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
- SQL语句中对时间字段进行区间查询
- Temporal线上部署
- Reference code series_1. Hello World in various languages
猜你喜欢
随机推荐
【MQ我可以讲一个小时】
sql statement - how to query data in another table based on the data in one table
110 MySQL interview questions and answers (continuously updated)
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
[Detailed explanation of ORACLE Explain]
mysql存储过程
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
Unity Framework Design Series: How Unity Designs Network Frameworks
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Sql解析转换之JSqlParse完整介绍
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
tf.keras.utils.pad_sequences()
Typec手机有线网卡网线转网口转接口快充方案
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
DVWA之SQL注入
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
Apache DButils使用注意事项--with modifiers “public“
centos7安装mysql5.7
Minio upload file ssl certificate is not trusted
快速掌握并发编程 --- 基础篇