Database creation, forms and queries

Apréndelo jugando

Responde estas preguntas para ganar energía, luego pesca y explora. Sin cuenta.

Para educadores: diapositivas de la lección, apuntes de repaso listos para usar sobre Database creation, forms and queries (Information and Communication Technology, Information Processing) — úsalos en tu lección, o presenta el tema como una actividad interactiva de clase que tus aprendices juegan como un juego en vivo.

Apuntes de la lección

Database Management Systems 數據庫管理系統

  • A database is an organised collection of related data. A Database Management System (DBMS) is software used to create, maintain, query and report on a database, e.g. Microsoft Access, LibreOffice Base, MySQL.
  • 數據庫是有組織的相關數據集合。數據庫管理系統(DBMS)是用來建立、維護、查詢及製作報告的軟件,例如 Microsoft Access、LibreOffice Base、MySQL。
  • Compared with separate files or spreadsheets, a DBMS reduces data redundancy (repeated data), keeps data consistent, controls access rights and lets many users share data.
  • 與獨立檔案或試算表比較,數據庫管理系統可減少數據冗餘(重複的數據)、保持數據一致、控制存取權限,並讓多名使用者共用數據。
  • A DBMS also makes it easy to search and sort large amounts of data with queries.
  • 數據庫管理系統亦可透過查詢輕易地搜尋及排序大量數據。

Designing a table 設計資料表

  • Each table stores one kind of thing, e.g. Student. Each field has a name, a data type and a size; each row is a record.
  • 每個資料表儲存一類事物,例如學生。每個欄位有名稱、數據類型及大小;每一列是一個記錄。
  • Common data types: Text (name, phone number), Number (integer or real, e.g. mark), Date/Time (date of birth), Boolean / Yes-No (has paid?), Currency (fee), AutoNumber (ID made automatically).
  • 常用數據類型:文字(姓名、電話號碼)、數字(整數或實數,例如分數)、日期/時間(出生日期)、布爾/是否(是否已付款?)、貨幣(費用)、自動編號(自動產生的編號)。
  • Choose a primary key whose value is unique for every record, e.g. StudentID.
  • 選擇一個主鍵,其值對每個記錄都獨一無二,例如學生編號。
  • Field properties help control data: validation rule (e.g. Mark between 0 and 100), input mask (e.g. a fixed pattern for a phone number), default value, required.
  • 欄位屬性有助控制數據:有效性規則(例如分數介乎 0 至 100)、輸入遮罩(例如電話號碼的固定格式)、預設值、必填。

Maintaining a database 維護數據庫

  • Add new records (e.g. a new student joins), edit records (a change of address) and delete records (a student leaves).
  • 新增記錄(例如新生入學)、編輯記錄(更改地址)及刪除記錄(學生離校)。
  • The structure can also be modified: add a field, change a field's size or data type.
  • 亦可修改結構:新增欄位、更改欄位大小或數據類型。
  • Changing a data type (e.g. Text to Number) may lose data that does not fit, so back up first.
  • 更改數據類型(例如由文字改為數字)可能令不符合的數據遺失,所以應先備份。

Designing a data entry form 設計數據輸入表單

  • A form shows one record at a time in a user-friendly layout, so users can enter data quickly and accurately without seeing the whole table.
  • 表單以方便使用的版面每次顯示一個記錄,讓使用者快速準確地輸入數據,而無須看見整個資料表。
  • Use suitable controls: text box (name), drop-down list / combo box (class), option buttons (one choice, e.g. sex), check box (yes/no), date picker (date).
  • 使用合適的控制項:文字方塊(姓名)、下拉式清單/組合方塊(班別)、選項按鈕(單一選擇,例如性別)、核取方塊(是/否)、日期選擇器(日期)。
  • Good form design: a clear title, clear labels, fields in a logical order (same as the paper form), instructions and examples, consistent fonts and colours, not too crowded.
  • 良好的表單設計:清楚的標題、清楚的標籤、欄位按合理次序排列(與紙本表格相同)、提供指示及例子、字型和顏色一致、不要太擠擁。
  • Forms support data control: drop-down lists allow only valid values; validation rules and error messages reject unreasonable data.
  • 表單有助數據控制:下拉式清單只容許有效值;有效性規則及錯誤訊息會拒絕不合理的數據。

Queries 查詢

  • A query extracts data from a table: it can select the fields to show, filter records with criteria and sort the results.
  • 查詢從資料表中提取數據:可選取要顯示的欄位、以條件篩選記錄,並把結果排序。
  • Criteria use relational operators (\texttt{=} \texttt{<>} \texttt{>} \texttt{<} \texttt{≥} \texttt{≤}) and logical operators (\texttt{AND} \texttt{OR} \texttt{NOT}).
  • 條件使用關係運算符(\texttt{=} \texttt{<>} \texttt{>} \texttt{<} \texttt{≥} \texttt{≤})及邏輯運算符(\texttt{AND} \texttt{OR} \texttt{NOT})。
  • A query can also add a calculated field, e.g. Total from Test1 plus Test2.
  • 查詢亦可加入計算欄位,例如由測驗一加測驗二得出總分。
  • The results are a view of the data; running the query again shows the latest data.
  • 查詢結果是數據的檢視;再次執行查詢會顯示最新數據。

Reading simple SQL 閱讀簡單的 SQL

  • SQL (Structured Query Language) is the standard language for querying databases.
  • SQL(結構化查詢語言)是查詢數據庫的標準語言。
  • \texttt{SELECT} lists the fields (\texttt{×} means all fields); \texttt{FROM} names the table; \texttt{WHERE} gives the condition; \texttt{ORDER BY} sorts (\texttt{ASC} ascending is the default, \texttt{DESC} descending).
  • \texttt{SELECT} 列出欄位(\texttt{×} 代表所有欄位);\texttt{FROM} 指明資料表;\texttt{WHERE} 給出條件;\texttt{ORDER BY} 排序(預設是 \texttt{ASC} 遞增,\texttt{DESC} 為遞減)。
  • Example: \texttt{SELECT Name, Mark} \texttt{FROM Student} \texttt{WHERE Class = '4A' AND Mark ≥ 50} \texttt{ORDER BY Mark DESC} lists 4A students who passed, highest mark first.
  • 例子:\texttt{SELECT Name, Mark} \texttt{FROM Student} \texttt{WHERE Class = '4A' AND Mark ≥ 50} \texttt{ORDER BY Mark DESC} 列出 4A 班合格的學生,分數最高者排先。
  • Text values go in quotes (\texttt{'4A'}); numbers do not (\texttt{50}). \texttt{LIKE 'Ch\%'} matches text starting with Ch; \texttt{BETWEEN 50 AND 70} includes both 50 and 70.
  • 文字值要加引號(\texttt{'4A'}),數字則不用(\texttt{50})。\texttt{LIKE 'Ch\%'} 配對以 Ch 開頭的文字;\texttt{BETWEEN 50 AND 70} 包括 50 和 70。
  • To trace a query: go through each record, keep it if the \texttt{WHERE} condition is true, then show the \texttt{SELECT} fields in \texttt{ORDER BY} order.
  • 追蹤查詢的方法:逐一檢查每個記錄,若 \texttt{WHERE} 條件成立便保留,然後按 \texttt{ORDER BY} 次序顯示 \texttt{SELECT} 的欄位。

Reports 報告

  • A report presents data from a table or query in a formatted, printable layout for an intended audience.
  • 報告以經格式化、可列印的版面,為目標讀者展示資料表或查詢中的數據。
  • Features: title, date, column headings, grouping (e.g. by class), sorting, summary values (count, total, average), page numbers.
  • 特點:標題、日期、欄標題、分組(例如按班別)、排序、摘要數值(數目、總和、平均值)、頁碼。
  • Match the report to its audience: a parent needs only their child's results; the principal needs a summary of every class.
  • 報告要配合讀者:家長只需要子女的成績;校長則需要各班的摘要。
  • Protect privacy: include only the fields the audience needs.
  • 保護私隱:只包括讀者所需的欄位。

Diapositivas

Sign up free to view the lesson slides

Step through every slide for this topic — plus flashcards and revision notes — with a free account.

Preguntas de práctica

Vista previa gratis — 8 de 34 preguntas. Regístrate para verlas todas.
  1. 1.What is a Database Management System (DBMS)? 甚麼是數據庫管理系統(DBMS)?

    Easy
    • ASoftware used to create, maintain and query databases 用來建立、維護及查詢數據庫的軟件
    • BA hardware device that stores data 儲存數據的硬件裝置
    • CA single table of data 單一的數據資料表
    • DA network that links computers 連接電腦的網絡
  2. 2.Which of the following are advantages of using a DBMS rather than separate spreadsheet files? (Select all that apply) 以下哪些是使用數據庫管理系統而非獨立試算表檔案的優點?(選出所有正確答案)

    Medium
    • ALess data redundancy 較少數據冗餘
    • BBetter control of access rights 更好地控制存取權限
    • CNo need for any backup 完全不需要備份
    • DData can be shared by many users 數據可供多名使用者共用
  3. 3.Match each field with its MOST suitable data type. 把每個欄位配對最合適的數據類型。

    Easy
    • Date of birth 出生日期
    • Monthly fee 每月費用
    • Has library card? 有沒有圖書證?
    • Surname 姓氏
    • Date/Time 日期/時間
    • Currency 貨幣
    • Boolean (Yes/No) 布爾(是/否)
    • Text 文字
  4. 4.Which field is the MOST suitable primary key for a table of library books? 以下哪個欄位最適合作為圖書館書籍資料表的主鍵?

    Easy
    • ATitle 書名
    • BBook ID 書籍編號
    • CAuthor 作者
    • DYear published 出版年份
  5. 5.A mobile phone number should be stored as a Number field so it takes less space. 手提電話號碼應以數字欄位儲存以節省空間。

    Easy

    True or false?

  6. 6.A field property rejects a mark unless it is between 0 and 100. What is this property called? 某欄位屬性會拒絕不在 0 至 100 之間的分數。這個屬性稱為甚麼?

    Easy
    • ADefault value 預設值
    • BPrimary key 主鍵
    • CValidation rule 有效性規則
    • DField size 欄位大小
  7. 7.A student leaves the school. Which database operation should be performed on the student's record? 一名學生離校。應對該學生的記錄進行哪項數據庫操作?

    Easy
    • AAdd 新增
    • BSort 排序
    • CChange the primary key of every record 更改每個記錄的主鍵
    • DDelete (or archive) 刪除(或存檔)
  8. 8.Changing a field's data type from Text to Number may cause some existing data to be lost. 把欄位的數據類型由文字改為數字,可能令部分現有數據遺失。

    Medium

    True or false?

Unlock all 34 questions, flashcards & more

Crea una cuenta gratis para ver todas las preguntas, las diapositivas, las tarjetas y los apuntes de repaso de este tema.

Exámenes anteriores

La práctica con exámenes anteriores de este tema llegará pronto.
Próximamente