当前位置:网站首页>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;
边栏推荐
- On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
- [Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
- 12个MySQL慢查询的原因分析
- STM32——DMA
- Linux系统安装mysql(rpm方式安装)
- MySQL优化之慢日志查询
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- Temporal客户端模型
- Pytorch教程Introduction中的神经网络实现示例
- Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
猜你喜欢
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
SQL行列转换
MYSQL下载及安装完整教程
Unity Framework Design Series: How Unity Designs Network Frameworks
DVWA之SQL注入
【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
Mysql——字符串函数
Mysql application cannot find my.ini file after installation
ES source code API call link source code analysis
matlab simulink欠驱动水面船舶航迹自抗扰控制研究
随机推荐
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
Kubernetes 证书可用年限修改
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
matlab abel变换图片处理
Flink sink ES 写入 ES(带密码)
[mysql improves query efficiency] Mysql database query is slow to solve the problem
可点击也可直接复制指定内容js
MySQL优化之慢日志查询
110 MySQL interview questions and answers (continuously updated)
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
pytorch中的一维、二维、三维卷积操作
1. 获取数据-requests.get()
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
Why use Flink and how to get started with Flink?
Mysql application cannot find my.ini file after installation
Reference code series_1. Hello World in various languages
mysql存储过程
tf.keras.utils.get_file()
Minio上传文件ssl证书不受信任
MYSQL一站式学习,看完即学完