数据库基础命令进阶版

在表内添加新字段

alter table 表名 add 字段名 类型 (长度)

修改表结构信息

1 方法1
2 alter table 表名 change 原字段 新字段 数据类型 (长度)
3 方法2
4 alter table 表名 modify 字段 数据类型(长度)

删除字段

alter table 表名 drop 字段

表名重命名

alter table 表名 rename 新表名

修改排序

新字段修改排序
alter table 表名 add 新加字段名 类型 (长度) after/first;
已有字段进行排序
alter table 表名 modify 字段名 类型 (长度) after/first;
重命名排序
alter table 表名 change 原字段 新字段 数据类型(长度) after/first;

after 在某个字段之后 
first  第一个

查看表内容

select * from 表名

数据库的增删改查

 1 增
 2 按照顺序添加
 3 insert into 表名 values(内容1,内容2)
 4 不按照顺序添加
 5 insert into 表名(字段名称) values(字段对应信息)
 6 删
 7 delete from 表名 where 条件
 8 改
 9 update 表名 set 字段=值 where 条件
10 查
11 查看所有数据
12 selsct * from 表名
13 查看某个字段数据
14 select 字段 from 表名
15 条件查找
16 select * from 表名 where 表名
17 按条件排序
18 升序
19 select * from 表名 order by 字段 
20 降序
21 select * from 表名 order by 字段 desc
22 先按字段1进行升序再按字段2进行降序
23 select * from 表名 orber by 字段1,字段2 desc;
24 限制出现个数
25 select * from 表名 order by 字段 desc limit 次数
26 偏移量 
27 select * from 表名 info order by 字段 偏移量,显示行数
28 模糊查找
29 select * from 表名 where 字段 like 条件%
30 查询去重
31 全部重复的进行去重

32 select distinct * from 表名
32 根据字段进行去重
33 select distinct 字段 from info

函数

1 sum       求和
2 avg       平均数
3 max       最大数
4 min       最小数
5 count     总和

连接

1 内连接
2 select distinct 表名.重复字段,字段,字段 from 1表名,2表名 where 表1.id=表2.id
3 外连接
4 左连接
5 select  distinct  表名 . id,name,字段,字段  from  表名  left  join  表名2  on  表名1 . id=表名2 . id ;
6 右连接
7 select  distinct  表名 . id,name,字段,字段  from  表名  right  join  表名2  on  表名1 . id=表名2 . id ;
原文地址:https://www.cnblogs.com/bnre/p/14148144.html