mysql 學習筆記4

來源:互聯網
上載者:User

標籤:

1. 自然串連
  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. 支援多表串連查詢

  3. 小結
    這個圖片, 傳上來就是這個樣子, 也不知道該怎麼旋轉, 如果有人知道怎麼弄的話, 懇請指教一下。

2. 重新導向
  1. mysql 除了可以將輸出結果返回到介面上, 也可以將輸出結果寫入到檔案中。
select * into outfile xxx from ....

需要注意的是,他不允許重寫已經存在的檔案, 但是可以建立新的檔案。預設使用’\t’區分欄位, 使用’\n’區分記錄, 可以修改。



3. 插入資料
  1. 使用 insert into 插入資料
  2. 當插入資料衝突的時候, 可以使用on duplicate key update 進行更新資料
  3. 另外需要注意, 我們可以使用select 查詢得到的子句的結果來進行插入
  4. default
  5. replace into 用於插入資料, 可以處理主鍵或者唯一索引衝突問題
  6. load data infile 可以用來設定從檔案中匯入資料, 以及資料的格式
4. 刪除資料
  1. delete from xxx limit n
  2. limit 用來限制記錄的數目, 可以與order by 配合使用
  3. 支援串連刪除, 可以用來類比外鍵約束
delete from one, two using one join two on xxx where xxx
5. 清空表
  1. truncate 直接將表格刪除然後建立一個表, 因而, 他的自動成長索引是從0 開始計算的。
  2. 而 delete from table 資料刪除了, 但是他們的自動成長的索引值不不會變為 0 的。
6. 更新表
  1. replace / insert on duplicate key update
  2. 條件更新, limit, order by & limit etc
  3. 支援多個表同時更新
update [one join two on xxx] set xxx where xxx

mysql 學習筆記4

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.