吴先生不爱吃辣

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

操作文件夹(数据库)

1 增:create database db1 charset utf8;
2 查:show databases;
3 改:alter database db1 charset latin1;
4 删除: drop database db1
5 
6 查看当前所在的数据库
7 select database();

操作文件(表)

1 先切换到文件夹下:use db1
2      增:create table t1(id int,name char);
3      查:show tables
4      改:alter table t1 modify name char(3);
5          alter table t1 change name name1 char(2);
6      删:drop table t1;
7 
8     查看表结构
9     describe t1;

修改表结构

https://book.apeland.cn/details/460/

表的内容操作

1,增

1 insert into [表名] values(1,'wu'),(2,'zhi'),(3,'bin');
2 insert into [] (列名,列名....) values (值,值,值....),(值,值,值....);
3 insert into [表1] (列名,列名...) select 列名,列名... from 表2; #将表1复制给表二
1 delete from []   #清空表
2 delete from [] where id =1 and name='wu';   #按条件删除
1 update [] set name = 'wang' where id =1;   #按条件修改
1 select * from []  #显示表中所有的列和数据
2 select * from [] where id >1 ; #按条件查询
其他
#对条件查询
slect * from [] where id > 5 and name != 'wuzhibin';
slect * from [] where id between 4 and 9;
select * from [] where id in (1,3,5);
select * from [表1] where id in (select id from  [表2]) # 条件是表2中的ID
1 #通配符查询
2 select * from [] where name like 'wu%' ; #以wu开头后面可以匹配多个字符
3 select * from [] where name like 'wu_' ; # 以wu开头后面最多匹配一个字符
1 #查询限制
2 select * from [] limit 5 ; #前面5行数据
3 select * from [] limit 4,5; #从第五行开始的5行
4 select * from [] limit 5 offset 4  # 从第武汉开始的5行
1 #排序查询
2 select * from [] order by [] asc;  #从小到大
3 select * from [] order by [] desc;  #从大到小
4 select * from [] order by [列1] asc[列2] desc ; 列1相等在根据列2排序
1 #两张表组合查询
2 select name from [表1]  union select name from [表2];  #自动去重
3 select name from [表1] union all select name from [表2]; #不去重
1 #连表操作
2  select t1.id ,t1.name ,t2.name from t1,t2 where t1.nid = t2.id; 

 

posted on 2020-04-07 21:35  吴先生不爱吃辣  阅读(115)  评论(0编辑  收藏  举报