markdown
データベースの基本md 32d7237
lecture/information/database/database-basics.lecture.n.md
Download PDF

データベースの基本きほん

date2026-07-14document_iddoc_8713b89d39f89f55dc2f5612128682d5descriptionデータベースとDBMSの役割、関係モデル、キー、整合性制約、正規化、トランザクションの基礎を説明する。prerequisitesHTTPの基本type講義statusactiverelateddata/lecture/information/database/database-portal.lecture.n.md / data/lecture/information/database/sql-basics.lecture.n.md / data/lecture/information/networks/http-basics.lecture.n.md / data/lecture/information/information-engineering-portal.lecture.n.md
informationdatabaseundergraduatelecture
data/lecture/information/database/database-portal.lecture.n.md

1導入どうにゅう

この講義こうぎでは、データベース管理かんりシステムによってデータを永続的えいぞくてきかつ一貫いっかんして管理かんりするための基本概念きほんがいねん説明せつめいする。とくに、関係かんけいモデルの構成要素こうせいようそ、キーと整合性制約せいごうせいせいやく正規化せいきか目的もくてき、トランザクションの ACID 特性とくせい導入どうにゅうする。

HTTP サーバは要求ようきゅう処理しょりし、必要ひつようおうじて表現ひょうげん生成せいせいするが、利用者りようしゃ商品しょうひん注文ちゅうもんなどのデータは個々ここ通信つうしん終了しゅうりょうしたあとにも保持ほじされる。このようなデータを複数ふくすうのプログラムや利用者りようしゃから安全あんぜん共有きょうゆうするには、保存形式ほぞんけいしきだけでなく、制約せいやく同時実行どうじじっこう障害しょうがいからの回復かいふく管理かんりする仕組しくみが必要ひつようである。

2データベースと DBMS

データベースDatabaseとは、特定とくてい目的もくてきしたがって組織化そしきかされ、永続的えいぞくてき管理かんりされるデータの集合しゅうごうである。

データベース管理かんりシステムDatabase management system; DBMSとは、データベースの定義ていぎ保存ほぞん検索けんさく更新こうしん、アクセス制御せいぎょ同時実行制御どうじじっこうせいぎょ障害回復しょうがいかいふくなどを提供ていきょうするソフトウェアである。データベースが管理対象かんりたいしょうとなるデータであるのにたいし、DBMS はそのデータを管理かんりする機構きこうである。

3関係かんけいモデルの構成要素こうせいようそ

関係かんけいモデルRelational modelでは、データを関係かんけいとして表現ひょうげんする。実装上じっそうじょうひょうとして表示ひょうじされることがおおいが、関係かんけいたんなる行列形式ぎょうれつけいしきのファイルではなく、属性ぞくせいとタプルからなる数学的すうがくてき構造こうぞうである。

  • 属性ぞくせいAttributeは、データを特徴とくちょうづける名前なまえいた項目こうもくである。
  • ドメインDomainは、ある属性ぞくせいあたい集合しゅうごうである。
  • タプルTupleは、各属性かくぞくせい対応たいおうするあたいをまとめた一件いっけんのデータである。
  • 関係かんけいスキーマRelation schemaは、関係名かんけいめい属性ぞくせい構成こうせいさだめる。
  • 関係かんけいインスタンスRelation instanceは、ある時点じてんでスキーマに適合てきごうするタプルの集合しゅうごうである。

たとえば、学生がくせい表現ひょうげんする関係かんけいスキーマをつぎのように記述きじゅつできる。

Student(student_id,name,department_id)

この場合ばあいstudent_idnamedepartment_id属性ぞくせいであり、個々ここ学生がくせい対応たいおうするあたいくみがタプルである。

4キー

スーパーキーSuperkeyとは、関係かんけいスキーマで許容きょようされるすべてのインスタンスにおいて、かくタプルを一意いちい識別しきべつすることが制約せいやくされた属性集合ぞくせいしゅうごうである。候補こうほキーCandidate keyとは、いずれの真部分集合しんぶぶんしゅうごうもスーパーキーではない極小きょくしょうなスーパーキーである。

しゅキーPrimary keyとは、候補こうほキーのうち、タプルの主要しゅよう識別子しきべつしとして選択せんたくしたものである。候補こうほキーは複数ふくすう存在そんざいるが、しゅキーとして選択せんたくするものはひとつである。

外部がいぶキーForeign keyとは、ある関係かんけい属性集合ぞくせいしゅうごうであり、そのあたい同一どういつまたはべつ関係かんけい候補こうほキーを参照さんしょうする。たとえば、Student.department_id学部がくぶ関係かんけいにある Department.department_id参照さんしょうすれば、学生がくせい所属学部しょぞくがくぶ関連かんれんづけられる。

5整合性制約せいごうせいせいやく

整合性制約せいごうせいせいやくIntegrity constraintとは、データベースの状態じょうたいたすべき条件じょうけんである。代表的だいひょうてき制約せいやくには、つぎのものがある。

  • ドメイン制約せいやくは、属性値ぞくせいち所定しょていのドメインへ制限せいげんする。
  • キー制約せいやくは、候補こうほキーのあたいがタプルを一意いちい識別しきべつすることを要求ようきゅうする。
  • 実体整合性じったいせいごうせいは、しゅキーの構成属性こうせいぞくせい欠損けっそんせず、かくタプルを識別しきべつできることを要求ようきゅうする。
  • 参照整合性さんしょうせいごうせいReferential integrityは、外部がいぶキーの非空ひくうあたい参照先さんしょうさき存在そんざいすることを要求ようきゅうする。

DBMS はこれらの制約せいやく違反いはんする更新こうしん拒否きょひし、または宣言せんげんされた参照動作さんしょうどうさしたがって関連かんれんするデータを更新こうしんする。ただし、データが現実世界げんじつせかい正確せいかく反映はんえいしているかどうかは、スキーマに表現ひょうげんされた制約せいやくだけでは完全かんぜん保証ほしょうできない。

6正規化せいきか目的もくてき

同一どういつ事実じじつ複数箇所ふくすうかしょ記録きろくすると、一部いちぶだけを更新こうしんすることによる不整合ふせいごう、データを追加ついかできない状況じょうきょう削除さくじょともなべつ事実じじつ消失しょうしつしょうる。これらをそれぞれ更新こうしん挿入そうにゅう削除さくじょ異常いじょうAnomalyという。

正規化せいきかNormalizationとは、属性間ぞくせいかん依存関係いぞんかんけいもとづいて関係かんけいスキーマを分解ぶんかいし、のぞましくない冗長性じょうちょうせい更新異常こうしんいじょう抑制よくせいするための設計過程せっけいかていである。正規化せいきかはあらゆる重複ちょうふく消去しょうきょすることではなく、依存関係いぞんかんけい適切てきせつ表現ひょうげんすることを目的もくてきとする。性能せいのう利用形態りようけいたいおうじて、意図的いとてき冗長性じょうちょうせい導入どうにゅうする非正規化ひせいきかもある。

7トランザクションと ACID

トランザクションTransactionとは、DBMS がひとつの論理的ろんりてき作業単位さぎょうたんいとしてあつか操作列そうされつである。たとえば送金そうきんでは、一方いっぽう口座こうざからの減額げんがく他方たほう口座こうざへの増額ぞうがく一体いったいとして処理しょりする必要ひつようがある。

トランザクションの代表的だいひょうてき特性とくせいを ACID と総称そうしょうする。

  • 原子性げんしせいAtomicity: トランザクションの全操作ぜんそうさ反映はんえいするか、いずれも反映はんえいしない。
  • 一貫性いっかんせいConsistency: トランザクションがただしく実行じっこうされると、制約せいやくたす状態じょうたいからべつのそのような状態じょうたい移行いこうする。
  • 独立性どくりつせいIsolation: 並行へいこうするトランザクションの干渉かんしょう制御せいぎょし、所定しょてい分離ぶんりレベルに対応たいおうする観測結果かんそくけっか提供ていきょうする。
  • 永続性えいぞくせいDurability: 確定かくていしたトランザクションの結果けっかは、以後いご障害しょうがいたいして保持ほじされる。

ACID は実装方式じっそうほうしきそのものではなく、トランザクション処理しょり目標もくひょうとする性質せいしつである。また、一貫性いっかんせいは DBMS だけで自動的じどうてきられるものではなく、適切てきせつ制約せいやくただしいトランザクション処理しょり必要ひつようとする。

8要点ようてん

  • データベースは組織化そしきかされたデータであり、DBMS はその定義ていぎ操作そうさ保護ほごになう。
  • 関係かんけいスキーマは属性ぞくせい構成こうせいさだめ、関係かんけいインスタンスはある時点じてんのタプルの集合しゅうごうである。
  • 候補こうほキー、しゅキー、外部がいぶキー、および整合性制約せいごうせいせいやくは、データの識別しきべつ関連かんれん表現ひょうげんする。
  • 正規化せいきかのぞましくない冗長性じょうちょうせい更新異常こうしんいじょう抑制よくせいし、トランザクションは複数ふくすう操作そうさ論理的ろんりてき単位たんいとして管理かんりする。

9つぎすす講義こうぎ

data/lecture/information/database/sql-basics.lecture.n.md

Database Fundamentals

data/lecture/information/database/database-portal.lecture.n.md

1Introduction

This lecture explains the fundamental concepts through which a database management system manages data persistently and consistently. In particular, it introduces the components of the relational model, keys and integrity constraints, the purpose of normalization, and the ACID properties of transactions.

An HTTP server processes requests and generates representations when needed, but data concerning users, products, and orders must remain available after individual communications end. Sharing such data safely among multiple programs and users requires mechanisms that manage not only storage formats but also constraints, concurrency, and recovery from failures.

2Databases and DBMSs

A databaseDatabase is a collection of data that is organized for a particular purpose and managed persistently.

A database management systemDatabase management system; DBMS is software that provides database definition, storage, querying, updating, access control, concurrency control, failure recovery, and related functions. A database is the data being managed, whereas a DBMS is the mechanism that manages it.

3Components of the Relational Model

The relational modelRelational model represents data as relations. Relations are often displayed as tables in implementations, but a relation is not merely a file arranged in rows and columns; it is a mathematical structure consisting of attributes and tuples.

  • An attributeAttribute is a named component that characterizes the data.
  • A domainDomain is the set of values that an attribute may take.
  • A tupleTuple is one data item containing a value corresponding to each attribute.
  • A relation schemaRelation schema specifies a relation name and its attribute structure.
  • A relation instanceRelation instance is the set of tuples that conforms to a schema at a particular time.

For example, a relation schema representing students can be written as follows.

Student(student_id,name,department_id)

Here, student_id, name, and department_id are attributes, and each collection of values corresponding to one student is a tuple.

4Keys

A superkeySuperkey is a set of attributes constrained to identify every tuple uniquely in every instance permitted by a relation schema. A candidate keyCandidate key is a minimal superkey: no proper subset of it is itself a superkey.

A primary keyPrimary key is the candidate key selected as the principal identifier of tuples. A relation may have multiple candidate keys, but only one is selected as its primary key.

A foreign keyForeign key is a set of attributes in one relation whose values reference a candidate key in the same or another relation. For example, if Student.department_id references Department.department_id in a department relation, it associates each student with a department.

5Integrity Constraints

An integrity constraintIntegrity constraint is a condition that database states must satisfy. Representative constraints include the following.

  • A domain constraint restricts an attribute value to its specified domain.
  • A key constraint requires candidate-key values to identify tuples uniquely.
  • Entity integrity requires the primary-key attributes to be present so that each tuple can be identified.
  • Referential integrityReferential integrity requires every non-null foreign-key value to exist in the referenced relation.

A DBMS rejects updates that violate these constraints or updates related data according to declared referential actions. Constraints expressed in a schema cannot, however, fully guarantee that data accurately reflects the real world.

6Purpose of Normalization

Recording the same fact in several locations can cause inconsistency when only one occurrence is updated, inability to insert data, or loss of a separate fact during deletion. These problems are called update, insertion, and deletion anomaliesAnomaly, respectively.

NormalizationNormalization is the design process of decomposing relation schemas according to dependencies among attributes in order to reduce undesirable redundancy and update anomalies. Normalization does not mean eliminating every duplication; its purpose is to represent dependencies appropriately. DenormalizationDenormalization may deliberately introduce redundancy in response to performance requirements or access patterns.

7Transactions and ACID

A transactionTransaction is a sequence of operations that a DBMS treats as one logical unit of work. A funds transfer, for example, must treat the debit from one account and the credit to another as one unit.

Four representative transaction properties are collectively called ACID.

  • AtomicityAtomicity: either all operations of a transaction take effect, or none do.
  • ConsistencyConsistency: when a transaction executes correctly, it moves the database from one constraint-satisfying state to another.
  • IsolationIsolation: interference among concurrent transactions is controlled to provide observations corresponding to a specified isolation level.
  • DurabilityDurability: the effects of a committed transaction remain preserved despite subsequent failures.

ACID describes desired properties of transaction processing rather than a particular implementation. Consistency is not obtained automatically from the DBMS alone; it also requires appropriate constraints and correct transaction logic.

8Key Points

  • A database is organized data, whereas a DBMS defines, operates on, and protects that data.
  • A relation schema specifies an attribute structure, while a relation instance is the set of tuples present at a particular time.
  • Candidate keys, primary keys, foreign keys, and integrity constraints express identification and relationships among data.
  • Normalization reduces undesirable redundancy and update anomalies, while transactions manage several operations as a logical unit.

9Next Lecture

data/lecture/information/database/sql-basics.lecture.n.md
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる