Why databases and the relational model
導入済み
17:15
データベースとリレーショナルモデル
データベース以前は、各プログラムが独自のフラットファイルを保持していました。各プログラムごとに1つのファイルです。店舗を想像してみてください。販売プログラム、請求書作成プログラム、配送プログラム…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| disk/dɪsk/ | A storage device that holds programs and data even when power is off. |
| database/ˈdeɪtəbeɪs/ | An organised collection of data that can be accessed and managed. |
| trees | Structures that organise data in levels, with items linked like branches. |
| file layout | The arrangement of data within a file, including the order of its fields. |
| table/ˈteɪbl/ | 表 |
| file-based approach | A way of storing data in separate files managed by individual programs. |
| relational database/rɪˈleɪʃənl ˈdeɪtəbeɪs/ | リレーショナルデータベース |
| flat files/flæt faɪlz/ | フラットファイル |
| Data redundancy/ˈdeɪtə rɪˈdʌndənsi/ | The same data, a customer's address, is held in several files, wasting storage and effort. |
| Data inconsistency/ˈdeɪtə ˌɪnkənˈsɪstənsi/ | The copies are updated separately, so they drift apart and nobody knows which is right. |
| Data dependence | Programs are tied to the file format , so a change to the layout means rewriting every program that uses the file. |
| file format | A way of organising and storing data in a file. |
| Integrity/ɪnˈteɡrɪti/ | The accuracy, completeness and protection of data against unauthorised or unintended alteration. |
| field/fiːld/ | フィールド |
| DBMS/ˌdiː biː em ˈes/ | Database management system: software for defining, storing, querying, updating and controlling access to a database. |
| data independence | The ability to change data storage without changing the programs that use it. |
| access rights/ˈækses raɪts/ | The actions a user or process is permitted to perform on a resource. |
| backups | Extra copies of data kept so it can be restored if lost or damaged. |
| joined | Combined using matching values in related fields from two tables. |
| rows | Horizontal lines in a table, each containing one record. |
| columns | Vertical lines in a table, each containing one field for every record. |
| relation/rɪˈleɪʃn/ | A table that stores data in rows and columns. |
| entity/ˈentɪti/ | エンティティ |
| record/ˈrekɔːd/ | レコード |
| tuple/ˈtuːpl/ | タプル |
| attribute/ˈætrɪbjuːt/ | 属性 |
| primary key/ˈpraɪməri kiː/ | 主鍵 |
| null/nʌl/ | A marker showing that a field has no value. |
| composite key/ˈkɒmpəzɪt kiː/ | 複合鍵 |
| candidate key/ˈkændɪdeɪt kiː/ | 候補鍵 |
| secondary key/ˈsekəndəri kiː/ | A non-primary field that is indexed for fast searching; indexing builds an index on a field so look-ups and joins run faster. |
| index/ˈɪndeks/ | A position marker or lookup structure used to locate data within a collection or database. |
| indexing/ˈɪndeksɪŋ/ | インデックス付け |
| foreign key/ˈfɒrən kiː/ | 外部鍵 |
| Relationships | Links between entities that show how their records are connected. |
| Referential integrity/ˌrefəˈrenʃl ɪnˈteɡrɪti/ | A rule requiring every foreign-key value to match an existing primary key. |
| One-to-one/wʌn tuː wʌn/ | A relationship where each record in either table links to at most one in the other. |
| One-to-many/wʌn tə ˈmeni/ | A relationship where one record links to many others, each linked back to at most one. |
| Many-to-many/ˈmeni tə ˈmeni/ | A relationship where many records in each table can link to many in the other. |
| orphan records | Records that refer to another record that no longer exists. |
| insert/ˈɪnsɜːt/ | To add a new item to a data structure, file or table. |
| delete/dɪˈliːt/ | To remove a record from a table. |
| cascade/kəˈskeɪd/ | Connecting stages one after another, so the output of one feeds the input of the next. |
IBMが望まなかった論文
- 1970年、IBMの研究員エドガー・コッドは、データを共有値によってリンクされた単純なテーブル形式で保存し、ディスク上の場所ではなく何が必要かを指定する言語でアクセスすることを提案する12ページの論文を発表した。
- IBMは既にファイルレイアウトに紐づいたツリー構造でデータを格納するデータベースを販売しており、数年間彼を無視した。ファイルレイアウトが変わるたびに、そのファイルに対応するすべてのプログラムを書き換える必要があった。
- 1980年代には、すべての銀行、航空会社、政府機関がコッドのテーブル方式へ移行していた。半世紀後でも、現在もそれらで動作している。
- この教訓とは、ファイルベースアプローチの問題点、それらを解決するリレーショナルデータベース、そして正確に用いるべき用語である。
ファイルベースアプローチ
- データベース以前、各プログラムは独自のフラットファイルを保持していた。販売プログラムには顧客ファイル、会計プログラムには別のファイル、配送プログラムには別のファイルがあった。
- 各ファイルには固定されたレイアウトがあり、プログラムのコードに依存しており、プログラム外からは中身を知ることはできなかった。
- 単一の小さなプログラムであれば機能する。問題は2つ目のプログラムが同じデータにアクセスしようとしたときに始まる。

3つのプログラム、顧客情報の3つのコピー

限界
- データ冗長性: 顧客住所といった同一のデータが複数のファイルに重複して格納され、ストレージ容量と労力が無駄になる。
- データ不一致: コピーが個別に更新されるため、内容が乖離し、どちらが正しいかわからなくなる。
- データ依存性: プログラムがファイル形式に依存しているため、レイアウトの変更に対して使用该ファイルのすべてのプログラムを書き換える必要がある。
- 整合性の維持が難しく、データを安全に共有できず、ファイル間での検索が遅く、フィールド単位でのセキュリティ設定ができない。

Storing a customer's address in several separate files leads to:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The same data held in many places (redundancy) can be updated separately and become inconsistent.
In a flat-file system the same data is often duplicated across files, which can become inconsistent when only one copy is updated.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
That redundancy and the resulting inconsistency is the core problem the relational model solves.
Which are limitations of the file-based approach? Select すべて that apply.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Redundancy, inconsistency and data dependence are the three named limitations. Tables and joins belong to the relational approach that replaces it.
リレーショナルデータベースが这些问题にどう答えるか
- リレーショナルデータベースは、DBMSと呼ばれる一つのソフトウェアによって管理されるテーブルにデータを格納し、すべてのプログラムがこれを利用する。
- 各事実は一度だけ格納されるため、冗長性と不一致が消滅する。住所を一处で変更すれば、すべてのプログラムがその変更を確認できる。
- プログラムは名前によってDBMSにデータを要求するため、ストレージの変更伴随伴随着program change without the programs changing: データ独立性。
- 整合性ルール、アクセス権限、バックアップは中央で強制され、任意のテーブルを他のどのテーブルでも検索または結合できる。

データは一つ、管理者も一つ

How does a relational database remove data inconsistency?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
One copy, one update, no drift. The DBMS gives every program the same current value.
用語:テーブル、行、列
- テーブル(関係)は行と列のグリッドであり、各エンティティ(データを保存する対象となるもの)ごとに一つのテーブルを持つ:
CUSTOMER、ORDER、PRODUCT。 - レコードとは一つの行、エンティティの一種实例です。形式名称はタプルである。
- フィールドとは一つの列、各レコードに関する情報の一つである。形式名称は属性である。

行はレコード、列はフィールドであり、一つの列が他テーブルに伸びている

Read a relational table with SELECT
A relational table is just rows (records) and columns (fields). WHERE keeps the rows that match a condition; SELECT then keeps only the columns you asked for.
用語:キー
- プライマリ キーとは、各レコードを一意に識別するフィールド、あるいは複数のフィールドの組み合わせであり、必ず null にならず、重複しない。複数のフィールドからなるプライマリ キーをコンポジット キーという。
- キャンディデート キーとは、プライマリ キーとして機能し得る任意のフィールドまたは組み合わせである。セカンダリ キーとは、高速な検索のためにインデックス付けされた非プライマリ フィールドであり、インデックス付けとは、フィールドにインデックスを作成して照合や結合を高速化することである。
- フォアリン キーとは、値が他テーブルのプライマリ キーと一致して二つを結びつけるフィールドである。略記法では、プライマリ キーは下線付きとし、フォアリン キーを注記する:
CUSTOMER(CustomerID, Name, Phone)
ORDER(OrderID, CustomerID, OrderDate) -- CustomerID is a foreign key → CUSTOMER

A primary key:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The primary key uniquely identifies each row. A foreign key is the one that links to another table.
Match each kind of key to what it is.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
The primary key identifies a row; a foreign key links to another table; composite = several fields together; candidate = a possible primary key.
A field whose value matches the primary key of another table is a ______ key.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The foreign key is what creates the relationship between two tables.
演習例:図書館データベースの構成要素を名付ける
- 図書館は自らの蔵書、会員、および各貸出を記録している。エンティティを特定し、それぞれにプライマリ キーを与え、外部キーも示せ。
- エンティティ:
BOOK、MEMBER、LOAN。プライマリ キー:BookID、MemberID、LoanID。これらは各レコードに対して一意であり、かつ空白にならないため選ばれた。タイトルや名前だけでは不十分である。なぜなら、複数の図書が同じタイトルを持つ可能性があるからである。 LOAN(LoanID, BookID, MemberID, DateOut, DateDue):BookIDとMemberIDは外部キーであり、それぞれ自身のテーブルのプライマリ キーと一致する。会員の電話番号はMEMBERに含めるべきであり、すべての貸出记录に必要ではない。

In LOAN(LoanID, BookID, MemberID, DateOut), BookID and MemberID are ____ keys.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Each matches the primary key of another table, BOOK and MEMBER, and links the loan to them.
関係性と参照整合性
- 関係とは二つのエンティティを結びつけるものである。一一対応:各会員には一つの図書カードがある。一対多:一人の会員が多数の貸出を持つ;各貸出は一人の会員に属する。多対多:一つの図書には多数の著者がおり、一つの著者は多数の図書を書く。
- 参照整合性とは、すべての外部キー値が、参照先テーブル内の既存のプライマリ キーと一致することを意味する。存在しない会員に対する貸出は認めず、孤児レコードも発生させない。
- DBMS がこれを強制する。未知の外部キーを含む挿入を拒否し、他のレコードがまだ参照しているレコードの削除も拒否する。
Referential integrity ensures that:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
It prevents orphan records — you cannot reference a primary key that does not exist.
Match each relationship to its type.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Count how many of each entity can be linked to one of the other. Many-to-many needs a link table to store.
演習例:参照整合性が防止すること
CUSTOMERテーブルから未済注文を三つ持つ顧客が削除される。参照整合性がどのように適用されるかを説明せよ。- 各注文の
CustomerIDは外部キーであり、既存の顧客と一致しなければならない。顧客を削除すると、三つの注文がもう存在しないレコードを指すことになり、孤児レコードが残る。 - そのため、DBMS は注文が削除されるか再割り当てされるまで、またはカスケード設定がされている場合は注文も同時に削除されるまで、顧客の削除を拒否する。いずれの場合でも、注文がいない顧客を指すことは決してない。
- このルールが何であるかを述べ、何がそれを破るか、そして DBMS はどうするかを答えよ。

Referential integrity allows a customer to be deleted while orders in another table still refer to that customer.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
That would create orphan records. The DBMS refuses the deletion, or cascades it to the orders, so every foreign key keeps pointing at an existing record.
採点基準として許容される定義
| 用語 | 定義 |
|---|---|
| エンティティ | データが保存される対象であり、一つのテーブルで表現される |
| 属性 | エンティティに関するデータの一項であり、一つの列 |
| タプル | テーブルの一行、一つのレコード |
| プライマリ キー | 各タプルを一意に識別する属性、あるいは属性の組み合わせ |
| キャンディデート キー | プライマリ キーとして選択され得る属性、あるいは属性の組み合わせ |
| セカンダリ キー | テーブルを高速に検索するためにインデックス付けされた属性 |
| フォアリン キー | 一つのテーブルにある属性であり、他テーブルのプライマリ キーとして関係を作る |
| 参照整合性 | すべての外部キー値が既存のプライマリ キーを参照する |
見落としやすいポイント
- タプルは行であり、属性は列である。これらを混同すると両方の得点が失われる。
- 「一意」だけでプライマリ キーを定義することはできない。各レコードを識別し、かつ必ず null にならないことが条件である。
- フォアリン キーは重複してもよい。一つの顧客、多数の注文である。重複してはいけないのはプライマリ キーのみである。
- セカンダリ キーは高速検索のためのものであり、識別のためのものではない。「第二のプライマリ キー」と呼ぶな。
理解できましたか
- ファイルベース方式は冗長、不一致、データ依存性に陥り、整合性、共有、検索、セキュリティが弱い。
- リレーショナル データベースは、一つの DBMS で管理されるテーブルに各事実を一度だけ格納するため、プログラムは格納方法に依存せず、ルールは中央で強制される。
- エンティティ → テーブル ・ タプル → レコード、行 ・ 属性 → フィールド、列 ・ プライマリ キーは識別、フォアリン キーは連結、キャンディデートは識別可能、セカンダリは検索用インデックス付き
- 参照整合性:すべての外部キーが既存のプライマリ キーと一致するため、孤児レコードは生じない
何が問題でしたか?この内容はサイトの運営チームだけが確認します。