IMOK
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- type: slide --- <style> .command { display: inline-block; font-size: 24px; color: black; background-color: white; padding: 7px; border-radius: 10px; margin: 5px; } </style> ## 計算機概論Lab-12 ### SQL ![image](https://hackmd.io/_uploads/rJ8EGF-NJe.png) <p>https://hackmd.io/@IMOK/Lab12</p> --- <img src="https://hackmd.io/_uploads/ryUSIqnJT.jpg" width=400 style="border-radius:1000px;"/> 講師: 賴昱有 --- ## BEFORE CLASS <font size = 6 >http://140.121.197.13/tutorial</font> <font size = 6 >先下載解壓縮後執行安裝</font> <font size = 6 ><span class="command">SQLServer2017-SSEI-Expr.exe</span></font> --- ## 什麼是資料庫 + <font size = 7 >結構</font> + <font size = 6 >Database</font> + <font size = 6 >Table</font> + <font size = 6 >Field</font> + <font size = 6 >Record</font> + <font size = 7 >CRUD</font> + <font size = 6 >Create</font> + <font size = 6 >Read</font> + <font size = 6 >Update</font> + <font size = 6 >Delete</font> ---- ![image](https://hackmd.io/_uploads/BkTiCnmVJe.png) ---- ## 關聯式資料庫 <font size = 5 >Relational Database Management System(RDBMS)</font> <img src= "https://hackmd.io/_uploads/rkrV5iXE1x.png" width=650 style="margin : 0px 0px 0px 0px"/> ---- ## 非關聯式資料庫 <font size = 5 >NoSQL (Not Only SQL)</font> + <font size = 7 >Key-Value Database</font> + <font size = 7 >Large-Scale Database</font> + <font size = 7 >Document Database</font> + <font size = 7 >Graph Database</font> + <font size = 7 >Time series database</font> + <font size = 7 >…</font> --- ## 匯入範例資料庫 + <font size = 6 >打開並複製 [instnwnd.sql](https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/databases/northwind-pubs/instnwnd.sql) 中所有內容</font> + <font size = 6 >打開 SSMS</font> + <font size = 6 >連接到 MYSQL Server</font> + <font size = 6 >Ctrl+N 打開指令編輯器</font> + <font size = 6 >貼上範例資料庫內容</font> + <font size = 6 >F5 執行所有指令</font> ---- ![image](https://hackmd.io/_uploads/BJI_ssmEyg.png) --- ## CRUD IN MYSQL + <font size = 6 >Create</font> + <font size = 6 ><span class="command">INSERT</span></font> + <font size = 6 >Read</font> + <font size = 6 ><span class="command">SELECT</span></font> + <font size = 6 >Update</font> + <font size = 6 ><span class="command">UPDATE</span></font> + <font size = 6 >Delete</font> + <font size = 6 ><span class="command">DELETE</span></font> ---- ## SELECT <font size = 6 >基本指令形式</font> ```sql= SELECT column1, column2 FROM table_name [WHERE conditions] [ORDER BY column1 order]; ``` <font size = 6 >e.g.</font> ```sql= SELECT CategoryID, CategoryName, Description, Picture FROM Northwind.dbo.Categories ``` ---- ```sql= SELECT * FROM Northwind.dbo.Categories WHERE CategoryID=1; ``` <img src= "https://hackmd.io/_uploads/HJB16smVkg.png" width=800 style="margin : 0px 0px 0px 0px"/> ---- <font size = 5 >查找 Description 是 S 開頭的</font> ```sql= SELECT * FROM Northwind.dbo.Categories WHERE Description LIKE 'S%'; ``` <font size = 5 >降序排序(DESC)、升序排列(ASC)</font> ```sql= SELECT * FROM Northwind.dbo.Categories WHERE Description LIKE 'S%' ORDER BY CategoryName DESC; ``` <font size = 5 >數資料筆數</font> ```sql= SELECT COUNT(*) FROM Northwind.dbo.Categories ``` --- ### INNER JOIN ```sql= SELECT * FROM Northwind.dbo.Categories INNER JOIN Northwind.dbo.Products ON Northwind.dbo.Categories.CategoryID = Northwind.dbo.Products.CategoryID ``` ---- <style> table { width: 80%; border-collapse: collapse; line-height: 1.5; /* 行距 */ } th, td { font-size: 18px; /* 字體大小 */ } </style> + <font size = 6 >Categories</font> | CategoryID | CategoryName | | ---------- | ------------ | | 1 | Drink | | 2 | Food | + <font size = 6 >Products</font> | CategoryID | CategoryName | CategoryID | | ---------- | ------------ | ---------- | | 1 | Beer | 1 | | 2 | Cola | 1 | | 3 | Bread | 2 | + <font size = 6 >Inner Join on CategoryID</font> | CategoryID | CategoryName | ProductID | ProductName | | ---------- | ------------ | --------- | ----------- | | 1 | Drink | 1 | Beer | | 1 | Drink | 2 | Cola | | 2 | Food | 3 | Bread | --- ### INSERT <font size = 6 >基本指令形式</font> ```sql= INSERT INTO table_name(column1, column2, ...) VALUES ('value1', 'value2', ...); ``` <font size = 6 >e.g.</font> ```sql= INSERT INTO Northwind.dbo.Categories VALUES ('test', 'test', 'test'); ``` --- ### UPDATE <font size = 6 >基本指令形式</font> ```sql= UPDATE table_name SET column1='value1', column2='value2' [WHERE conditions]; ``` <font size = 6 >e.g.</font> ```sql= UPDATE Northwind.dbo.Categories SET CategoryName='test2' WHERE CategoryName='test' ``` --- ### DELETE <font size = 6 >基本指令形式</font> ```sql= DELETE FROM table_name [WHERE conditions]; ``` <font size = 6 >e.g.</font> ```sql= DELETE FROM Northwind.dbo.Categories WHERE CategoryName='test2'; ``` --- ## 延伸閱讀 <font size = 7 >[w3schools-sql](https://www.w3schools.com/sql/) </font> --- ## 作業網站 作業做完請上傳到 http://140.121.197.13/tutorial 並且注意上傳時間限制、檔名、其他規範 上課時提前做完可以直接給助教 demo 登記 就不需要上傳 demo 過的部分 ---- ## Question 1 <font size=6> 使用 SQL 指令查詢 Northwind 資料庫內的 Order 資料表 EmployeeID=5 的資料 </font> ---- ## Question 2 <font size=6>使用 SQL 指令查詢 Northwind 資料庫內的 Order 資料表 EmployeeID 介於 3 到 6 的資料 並且將查詢結果根據 EmployeeID 進行由大至小的排序 </font> + <font size=6 color="#ff0000">[HINT]</font> <font size=6> \>\= AND \<\= or BETWEEN…AND…</font> ---- ## Question 3 <font size=6>使用 SQL 指令計算 Northwind 資料庫內的 Order 資料表共有幾筆訂單。 </font> + <font size=6 color="#ff0000">[HINT]</font><font size=6> SELECT COUNT</font> ---- ## Question 4 <font size=6>使用 SQL 指令在 Northwind 資料庫內的 Products 資料表 新增一筆 Products 的資料,內容不限。</font> + <font size=6 color="#ff0000">[HINT]</font><font size=6> 需注意資料欄位內的資料型態</font> ---- ## Question 5 <font size=5>使用 SQL 指令在剛剛新增的 Products 資料將 ProductName 設定為 Egg,UnitPrice設定為 12.00。 </font> ---- ## Question 6 <font size=5>使用 SQL 指令刪除 Northwind 資料庫內的 Products 資料表你所新增的 Products 資料 </font> ---- ## Question 7 <font size=5>使用 SQL 指令將 Northwind 資料庫內 Categories、Order Details 以及 Products 資料表進行結合 查詢出每筆訂單詳細的 產品名稱 (ProductName)、種類名稱(CategoryName) 及單位價格 (UnitPrice) </font> + <font size=6 color="#ff0000">[HINT]</font> <font size=6>(nested) INNER JOIN</font>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully