码迷,mamicode.com
首页 > 数据库 > 详细

常用数据库语句(4)

时间:2018-07-18 17:16:18      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:事务处理   run   自动提交   联合查询   联合   author   com   结果   sum   

分组
SELECT
count(*) sum,
book_name,
bokk_author
FROM
book
GROUP BY
bokk_author
HAVING
sum > 3;

drop truncate delete 的简单区别(待完善)

Dorp 表结构都会删掉,全部删掉
Truncate 清空表数据,删除整个数据
Delete 删除数据,删除部分职能用delete

truncate table author
drop table test
delete from author where author_name = "hhq"

Union\union all 联合查询
union和union all关键字都是将两个结果集合并为一个,两个表的列数要相同
Union 可以去重,union all 显示所有

select bokk_author from book union all select author_name from author;
select bokk_author from book union select author_name from author;


事务处理

Mysql事务处理主要有两种方法:
1、用begin,rollback,commit来实现

Begin 开始一个事务
Rollback事务回滚
Commit事务确认

begin;
delete from author;
select from author;
ROLLBACK;
SELECT
from author;
COMMIT;
2、直接用set改变mysql的自动提交模式
Set autocommit=0 禁止自动提交
Set autocommit=1 开启自动提交

常用数据库语句(4)

标签:事务处理   run   自动提交   联合查询   联合   author   com   结果   sum   

原文地址:http://blog.51cto.com/13496943/2146808

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!