標籤:
1. 自然串連
通過mysql 自己的判斷完成串連的過程, 而不需要指定串連條件, mysql使用多個表中的相同欄位作為串連條件。
- 內串連 natural join ? inner join using
- 左外串連 natural left join ? left join using
- 右外串連 natural right join ? right join using
ps: left join 和 right join 之間是可以相互轉化的
支援多表串連查詢
小結
這個圖片, 傳上來就是這個樣子, 也不知道該怎麼旋轉, 如果有人知道怎麼弄的話, 懇請指教一下。
2. 重新導向
- mysql 除了可以將輸出結果返回到介面上, 也可以將輸出結果寫入到檔案中。
select * into outfile xxx from ....
需要注意的是,他不允許重寫已經存在的檔案, 但是可以建立新的檔案。預設使用’\t’區分欄位, 使用’\n’區分記錄, 可以修改。
3. 插入資料
- 使用 insert into 插入資料
- 當插入資料衝突的時候, 可以使用on duplicate key update 進行更新資料
- 另外需要注意, 我們可以使用select 查詢得到的子句的結果來進行插入
- default
- replace into 用於插入資料, 可以處理主鍵或者唯一索引衝突問題
- load data infile 可以用來設定從檔案中匯入資料, 以及資料的格式
4. 刪除資料
- delete from xxx limit n
- limit 用來限制記錄的數目, 可以與order by 配合使用
- 支援串連刪除, 可以用來類比外鍵約束
delete from one, two using one join two on xxx where xxx
5. 清空表
- truncate 直接將表格刪除然後建立一個表, 因而, 他的自動成長索引是從0 開始計算的。
- 而 delete from table 資料刪除了, 但是他們的自動成長的索引值不不會變為 0 的。
6. 更新表
- replace / insert on duplicate key update
- 條件更新, limit, order by & limit etc
- 支援多個表同時更新
update [one join two on xxx] set xxx where xxx
mysql 學習筆記4