Data organisation and data control
遊んで学ぼう
問題に答えてエネルギーを集めたら、釣りや探検を楽しもう。アカウント不要。
レッスンノート
The data hierarchy 數據層級
- Data is organised in a hierarchy from smallest to largest: character → field → record → file → database.
- 數據按層級由小至大組織:字元 → 欄位 → 記錄 → 檔案 → 數據庫。
- Character: a single letter, digit or symbol, e.g. 'A', '7', '@'. Field: one item of data about something, e.g. a student's name.
- 字元:單一字母、數字或符號,例如「A」、「7」、「@」。欄位:關於某事物的一項數據,例如學生姓名。
- Record: a set of related fields about one person or thing, e.g. all the details of one student.
- 記錄:關於一個人或一件事物的一組相關欄位,例如一名學生的全部資料。
- File (or table): a collection of related records, e.g. all students in the school. Database: a collection of related files, e.g. student, subject and fee files.
- 檔案(或資料表):一組相關記錄,例如全校學生。數據庫:一組相關檔案,例如學生、科目及學費檔案。
Key fields 關鍵欄位
- A key field (primary key) holds a value that is unique for every record, so each record can be identified.
- 關鍵欄位(主鍵)的值對每一個記錄都是獨一無二的,因此可以識別每個記錄。
- Good key fields: student ID, HKID number, product code. Poor key fields: name, class, date of birth — these can repeat.
- 良好的關鍵欄位:學生編號、身份證號碼、貨品編號。不良的關鍵欄位:姓名、班別、出生日期——這些可能重複。
- Records are often sorted by the key field so that they can be found quickly.
- 記錄通常會按關鍵欄位排序,以便快速找到。
Sequential access 順序存取
- In sequential access, records are read one after another from the beginning until the required record is found.
- 在順序存取中,記錄由開頭逐一讀取,直至找到所需記錄。
- Example medium: magnetic tape. Used when most records are processed each time, e.g. monthly payroll, utility bills, backups.
- 例子媒體:磁帶。適用於每次處理大部分記錄的情況,例如每月計算薪金、水電費單、備份。
- Advantages: simple, cheap, efficient when all records are processed in order (batch processing).
- 優點:簡單、便宜,當按次序處理所有記錄時很有效率(批次處理)。
- Disadvantages: slow to find a single record; inserting or deleting a record usually means rewriting the file.
- 缺點:尋找單一記錄很慢;插入或刪除記錄通常需要重寫整個檔案。
Direct (random) access 直接(隨機)存取
- In direct access, the system goes straight to the required record without reading the ones before it (using an address or an index).
- 在直接存取中,系統直接前往所需記錄而不需讀取之前的記錄(利用位址或索引)。
- Example media: hard disk, SSD, flash memory. Used when individual records are needed quickly, e.g. ATM balance enquiry, airline booking, library catalogue.
- 例子媒體:硬碟、固態硬碟、快閃記憶體。適用於需要快速取得個別記錄的情況,例如自動櫃員機查詢餘額、機票訂位、圖書館目錄。
- Advantages: fast retrieval of any record; easy to update, insert or delete one record.
- 優點:可快速讀取任何記錄;易於更新、插入或刪除單一記錄。
- Disadvantages: more complex and more expensive storage; less efficient if every record must be processed in order.
- 缺點:較複雜及儲存成本較高;若須按次序處理所有記錄則效率較低。
Why data needs controlling 為何需要控制數據
- "Garbage in, garbage out" (GIGO): if wrong data is entered, the output will also be wrong, however good the program is.
- 「垃圾入,垃圾出」:若輸入錯誤數據,無論程式多好,輸出亦會是錯的。
- Errors come from typing mistakes, transcription errors (copying wrongly), transposition errors (e.g. 5162 typed as 5612) and transmission errors (noise changes bits).
- 錯誤來自打字錯誤、抄寫錯誤、換位錯誤(例如 5162 打成 5612)及傳送錯誤(雜訊令位元改變)。
- Data control aims to prevent errors (verification) and detect errors (validation, parity check).
- 數據控制旨在防止錯誤(核實)及偵測錯誤(有效性檢驗、奇偶校驗)。
Validation 有效性檢驗
- Validation is an automatic check by the computer that data is reasonable and follows the rules. It cannot prove data is correct.
- 有效性檢驗是電腦自動檢查數據是否合理及符合規則,但不能證明數據正確。
- Range check: value within limits, e.g. mark 0–100. Type check: correct data type, e.g. age must be a number.
- 範圍檢查:數值在限制之內,例如分數 0–100。類型檢查:數據類型正確,例如年齡必須是數字。
- Length check: correct number of characters, e.g. HK phone number has 8 digits. Presence check: a required field is not left empty.
- 長度檢查:字元數目正確,例如香港電話號碼有 8 位數字。存在檢查:必填欄位不可留空。
- Format check: data matches a pattern, e.g. date DD/MM/YYYY. Check digit: an extra digit calculated from the others, e.g. the digit in brackets on an HKID card or an ISBN.
- 格式檢查:數據符合某個格式,例如日期 DD/MM/YYYY。核對數位:由其他數字計算出的額外數字,例如身份證括號內的數字或 ISBN。
- A mark of 67 entered as 76 passes a range check — validation cannot catch every error.
- 把分數 67 輸入成 76 仍會通過範圍檢查——有效性檢驗不能找出所有錯誤。
Verification 核實
- Verification checks that data has been copied or entered exactly as in the original source.
- 核實是檢查數據是否與原始來源完全一致地抄寫或輸入。
- Double entry: data is entered twice (e.g. a new password typed twice) and the two copies are compared.
- 雙重輸入:數據輸入兩次(例如新密碼輸入兩次),然後比較兩份是否相同。
- Visual check (proofreading): a person compares the entered data with the source document on screen.
- 目視檢查(校對):由人把已輸入的數據與原始文件在螢幕上比較。
- Verification does not check whether the original data was sensible — a wrong value on the form is still wrong.
- 核實不會檢查原始數據是否合理——表格上本身錯誤的數值仍然是錯的。
Parity checking 奇偶校驗
- A parity bit is an extra bit added to a group of bits so errors in transmission can be detected.
- 奇偶位元是加在一組位元上的額外位元,用以偵測傳送中的錯誤。
- Even parity: the total number of 1s (including the parity bit) must be even. Odd parity: the total must be odd.
- 偶校驗:1 的總數(包括奇偶位元)必須是雙數。奇校驗:總數必須是單數。
- Example: data 1011001 has four 1s. Even parity bit is 0; odd parity bit is 1.
- 例子:數據 1011001 有四個 1。偶校驗位元=0;奇校驗位元=1。
- Limitation: if two bits change, the parity is still correct, so the error is not detected; parity also cannot show which bit is wrong.
- 限制:若兩個位元同時改變,奇偶性仍然正確,錯誤便不能被偵測;奇偶校驗亦不能指出哪個位元出錯。
スライド
練習問題
無料プレビュー — 34問中8問。すべて見るには登録を。
1.Arrange the levels of the data hierarchy from SMALLEST to LARGEST. 把數據層級由最小至最大排列。
Easy- Character 字元
- Field 欄位
- Record 記錄
- File 檔案
- Database 數據庫
2.In a school's student file, the class of one student (e.g. 4C) is a ……. 在學校的學生檔案中,一名學生的班別(例如 4C)是一個……。
Easy- AField 欄位
- BRecord 記錄
- CFile 檔案
- DDatabase 數據庫
3.A collection of related records, such as all the books in a library, is called a ……. 一組相關記錄,例如圖書館所有書籍,稱為……。
Easy- ACharacter 字元
- BFile 檔案
- CField 欄位
- DKey field 關鍵欄位
4.Which of the following is the MOST suitable key field for a file of mobile phone customers? 以下哪項最適合作為手提電話客戶檔案的關鍵欄位?
Easy- ACustomer name 客戶姓名
- BDate of joining 登記日期
- CCustomer account number 客戶戶口號碼
- DDistrict 地區
5.Two records in the same file may have the same value in the key field. 同一檔案中的兩個記錄可以有相同的關鍵欄位值。
EasyTrue or false?
6.Which storage medium supports ONLY sequential access? 哪種儲存媒體只支援順序存取?
Easy- AUSB flash drive USB 快閃記憶體
- BHard disk 硬碟
- CSolid-state drive 固態硬碟
- DMagnetic tape 磁帶
7.Which of the following applications requires direct access? 以下哪個應用需要直接存取?
Easy- AChecking an Octopus card balance at a machine 在機器查詢八達通餘額
- BWeekly backup of a server 伺服器的每週備份
- CMonthly payroll for all staff 全體員工的每月薪金
- DPrinting all students' report cards 列印全體學生的成績表
8.Which of the following are advantages of direct access over sequential access? (Select all that apply) 以下哪些是直接存取相對順序存取的優點?(選出所有正確答案)
Medium- AAny record can be retrieved quickly 可快速讀取任何記錄
- BA single record is easy to update 容易更新單一記錄
- CThe storage medium is always cheaper 儲存媒體必定較便宜
- DRecords can be inserted without rewriting the whole file 插入記錄時不需重寫整個檔案