首页 > 数据库技术 > 详细

常用数据库语句(4)

时间:2018-07-18 16:51:54      阅读:160      评论:0      收藏:0      [点我收藏+]
分组
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)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!