常用數據庫語句(4)
阿新 • • 發佈:2018-07-18
常用 sel 分組 union和 開啟 cat 聯合查詢 表結構 語句 分組
SELECT
count(*) sum,
book_name,
bokk_author
FROM
book
GROUP BY
bokk_author
HAVING
sum > 3; Union 可以去重,union all 顯示所有
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關鍵字都是將兩個結果集合並為一個,兩個表的列數要相同
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)