目 次

目 次
はじめに
第 1 部 データベース設計
第 1 章 情報システム化計画 ························································································· 19
1.1
1.2
P−D−S サイクル ······························································································ 19
計画・実施・評価 ·································································································· 22
(1)
計画段階 ·············································································································· 22
(2)
実施段階 ·············································································································· 23
(3)
評価段階 ·············································································································· 25
第 2 章 データベース設計 ······························································································ 26
2.1
設計はデータが中心 ··························································································· 26
2.2
データベース設計の手順 ···················································································· 28
2.2.1
要件定義 ·············································································································· 30
2.2.2
データベースの論理構造の設計 ········································································ 33
2.2.3
データベースの物理構造の設計 ········································································ 35
2.2.4
アプリケーション開発 ·························································································· 37
2.2.5
チューニング ········································································································ 38
2.3
三層スキーマ構造 ······························································································· 40
2.3.1
外部層(外部モデル) ···························································································· 40
2.3.2
概念層(論理データモデル) ················································································· 41
2.3.3
内部層(物理データモデル) ················································································· 41
7
第 2 部 論理設計
第 1 章 データベース論理設計の基礎 ········································································ 45
1.1
論理設計の目的 ·································································································· 45
1.2
正規化 ·················································································································· 46
1.3
テーブル設計 ······································································································· 49
1.4
制 約 ··················································································································· 51
1.4.1
制約の重要性 ······································································································ 51
1.4.2
制約の処理 ·········································································································· 52
(1)
ユーザによる処理 ······························································································· 52
(2)
データベース機能の利用 ···················································································· 53
1.4.3
制約の種類 ·········································································································· 53
1.5
ナル値 ·················································································································· 56
第 2 章 論理データベース設計の基本セオリー························································· 58
8
2.1
テーブル設計 ······································································································· 58
2.1.1
フィールドの選択とフィールド属性の決定 ·························································· 59
2.1.2
テーブルの構成 ··································································································· 59
2.1.3
重複性の排除(正規化) ······················································································· 59
2.1.4
キーの検討 ·········································································································· 60
2.1.5
参照制約の検討 ·································································································· 62
2.2
正規化 ·················································································································· 62
2.2.1
正規化のステップ ································································································ 62
(1)
非正規形 ·············································································································· 62
(2)
第 1 正規形·········································································································· 64
(3)
第 2 正規形·········································································································· 66
(4)
第 3 正規形·········································································································· 73
(5)
第 4 正規形·········································································································· 75
(6)
第 5 正規形·········································································································· 77
2.2.2
正規化の度合 ······································································································ 77
2.2.3
正規化の利点 ······································································································ 80
2.3
制 約 ··················································································································· 84
2.3.1
NOT NULL(非ナル値)制約 ·············································································· 84
2.3.2
ユニーク性(一意性)制約 ····················································································· 85
2.3.3
主キー制約 ·········································································································· 86
2.3.4
参照制約 ·············································································································· 86
(1)
用語······················································································································ 86
(2)
参照制約の影響 ·································································································· 88
2.3.5
検査(チェック)制約 ······························································································ 92
2.3.6
省略時(デフォルト)制約 ······················································································ 92
2.4
インデックス ········································································································· 92
2.4.1
インデックスの構造と必要性 ·············································································· 92
2.4.2
インデックスの性質 ····························································································· 93
(1)
ユニーク性 ··········································································································· 93
(2)
クラスター化 ········································································································ 94
(3)
インデックスを構成するフィールド数 ·································································· 95
2.4.3
データへのアクセス ····························································································· 96
(1)
インデックスが定義されていない場合································································ 96
(2)
ユニーク・インデックスに合致した場合······························································· 96
(3)
クラスター化インデックスに合致した場合 ·························································· 97
(4)
非クラスター化インデックスに合致する場合 ····················································· 99
(5)
クラスター化インデックスに合致しない場合 ···················································· 101
(6)
インデックスへのアクセスだけで完了する ······················································· 101
2.4.4
インデックス設計の手順 ··················································································· 102
(1)
インデックスの必要性の検討 ············································································ 102
(2)
基本的なインデックス候補の選択 ···································································· 103
(3)
追加インデックス候補の選択············································································ 104
(4)
クラスター化インデックスの検討 ······································································ 105
(5)
インデックス候補の取捨選択と決定 ································································· 106
(6)
重要な問い合わせについては個別に追加のインデックスを検討する ··········· 106
(7)
インデックスの物理設計を行う ········································································· 107
(8)
インデックスの有効性を検証する ····································································· 107
2.4.5
インデックスの決定 ··························································································· 107
9
2.5
ビューとシノニム ································································································ 108
2.5.1
ビューとは ·········································································································· 108
2.5.2
ビューを作る理由 ······························································································ 111
2.5.3
ビューの分類 ····································································································· 115
(1)
削除可能なビュー ······························································································ 115
(2)
更新可能なビュー ······························································································ 116
(3)
挿入可能なビュー ······························································································ 116
(4)
読み取り専用のビュー ······················································································· 116
2.5.4
シノニム ············································································································· 117
第 3 章 主要 DBMS 製品の支援機能 ········································································· 118
3.1
テーブル ············································································································· 118
3.1.1
ORACLE における支援機能 ··········································································· 118
(1)
VARCHAR2 の使用について ········································································· 118
(2)
バイト文字セットと日本語データ・フィールド ····················································· 120
(3)
NUMBER の使用について ············································································· 120
3.1.2
SQL Server における支援機能 ······································································· 121
3.1.3
DB2 における支援機能 ···················································································· 121
3.2
クラスタリング ···································································································· 122
3.3
ハッシング·········································································································· 123
第 4 章 論理データベース設計の実践テクニック ···················································· 125
4.1
ER モデルから論理データベースへ ································································· 125
4.1.1
ER モデル·········································································································· 125
4.1.2
エンティティ(実体) ····························································································· 126
4.1.3
リレーションシップ(関連) ··················································································· 127
4.1.4
ER モデルの作成 ······························································································ 128
4.1.5
エンティティ図の作成 ························································································ 129
(1)
エンティティの洗い出しと関連図の作成 ··························································· 129
(2)
核エンティティによる基本キーの決定 ······························································ 133
(3)
特質エンティティによる基本キーの決定と外部キーの認識 ···························· 133
(4)
N:M の関係にあるエンティティの間に関連エンティティを作る ······················ 134
(5)
関連エンティティを見つけて,基本キーの決定と外部キーの認識 ················· 134
10
(6)
参照の整合性に基づいて参照制約を決める ··················································· 135
4.2
正規化 ················································································································ 137
4.2.1
例題(演習④ 再掲) ··························································································· 137
4.2.2
データの分析 ····································································································· 138
4.2.3
エンティティ分析 ································································································ 139
4.2.4
正規化の検討(演習④ 解答例) ······································································· 141
4.3
テーブル設計 ····································································································· 145
4.3.1
フィールドの候補 ······························································································· 146
(1)
キー・フィールドの選択······················································································ 146
(2)
フィールドとして定義しない情報 ······································································· 149
(3)
フィールドとして定義した方がよい情報 ···························································· 150
(4)
フィールドの分割/統合 ······················································································ 153
(5)
頻繁に結合されるフィールドは基本テーブルに含める···································· 157
(6)
ナル値および可変長フィールドはテーブルの最後のフィールドにする
··························································································································· 157
(7)
予備フィールドは不要 ······················································································· 158
4.3.2
フィールドのデータ形式····················································································· 158
(1)
DBMS に固有のデータ型は避ける ································································· 158
(2)
可変長形式は注意が必要である······································································ 158
(3)
データ形式を統一する ······················································································ 159
(4)
フィールドに適したデータ形式を選択する ······················································· 160
(5)
日付・時刻は場合によっては二重に持つ ························································· 160
第 3 部 物理設計
第 1 章 物理データベース設計の基本セオリー······················································· 163
1.1
物理設計の目的 ································································································ 163
1.1.1
論理設計から物理設計へ ················································································· 163
1.1.2
物理設計の手順 ································································································ 164
(1)
データベース関連の定義 ·················································································· 165
(2)
テーブルの定義およびビューの定義 ································································ 166
11
(3)
権限の定義 ········································································································ 166
(4)
シノニムの定義 ·································································································· 166
(5)
データのロード ··································································································· 166
(6)
インデックスの定義 ··························································································· 166
(7)
チューニング ······································································································ 167
1.2
テーブルの定義 ································································································· 167
1.2.1
テーブル定義のヒント ························································································ 167
(1)
フィールドを定義した順番はアプリケーションとは独立している ····················· 167
(2)
フィールドの使用頻度を考慮する ····································································· 167
(3)
可変長/ナル値を許すフィールドは固定長フィールドの後ろに定義する
··························································································································· 168
(4)
同時に更新される可能性のあるフィールドはできるだけ隣接させる
··························································································································· 169
1.2.2
テーブル定義情報の変更がプログラムへ及ぼす影響 ···································· 169
1.3
ビューとシノニム ································································································ 170
1.3.1
定義する時点 ···································································································· 170
(1)
テーブルの定義時 ····························································································· 170
(2)
SQL 文の設計時 ······························································································· 170
1.3.2
考慮点 ················································································································ 171
1.3.3
シノニムの使用(スキーマとオブジェクト) ························································· 171
1.4
インデックス ······································································································· 173
1.4.1
インデックスの効果的な使い方 ········································································ 173
1.4.2
作成/消去の時点 ······························································································· 174
(1)
いつ作成するか ································································································· 174
(2)
いつ消去するか ································································································· 175
(3)
統計情報の取得時点 ························································································ 176
1.4.3
一般的な考慮点 ································································································ 176
第 2 章 主要 DBMS 製品の支援機能 ········································································· 180
2.1
データベースの定義 ·························································································· 180
2.1.1
ORACLE における支援機能 ··········································································· 180
2.1.2
SQL Server における支援機能 ······································································· 189
12
2.1.3
DB2 における支援機能 ···················································································· 191
2.2
テーブルの定義 ································································································· 194
2.2.1
ORACLE における支援機能 ··········································································· 194
(1)
CREATE TABLE 文 ······················································································· 194
2.2.2
SQL Server における支援機能 ······································································· 198
2.2.3
DB2 における支援機能 ···················································································· 199
2.3
ビュー ················································································································· 200
2.3.1
ビューの定義 ····································································································· 200
2.3.2
ORACLE における支援機能 ··········································································· 201
2.3.3
SQL Server における支援機能 ······································································· 204
2.3.4
DB2 における支援機能 ···················································································· 204
2.4
インデックス ······································································································· 205
2.4.1
ORACLE における支援機能 ··········································································· 205
2.4.2
SQL Server における支援機能 ······································································· 206
2.4.3
DB2 における支援機能 ···················································································· 208
2.5
権限の設計 ········································································································ 209
2.5.1
権限の種類 ········································································································ 209
2.5.2
データベース・オブジェクト作成の権限 ···························································· 211
2.5.3
ユーザへの特権の授与····················································································· 211
2.5.4
安全保護機能 ···································································································· 214
2.5.5
ロール ················································································································ 215
2.6
制 約 ················································································································· 216
2.6.1
制約の定義 ········································································································ 216
2.6.2
ORACLE における支援機能 ··········································································· 217
2.6.3
SQL Server における支援機能 ······································································· 227
2.6.4
DB2 における支援機能 ···················································································· 232
13
第 4 部 パフォーマンス設計
(物理データベース設計の実践テクニック)
第 1 章 オプティマイザー ······························································································ 239
1.1
データベース設計······························································································ 239
1.2
オプティマイザー ······························································································· 240
1.2.1
オプティマイザーの種類 ···················································································· 242
(1)
ルール・ベース··································································································· 242
(2)
コスト・ベース ····································································································· 242
1.2.2
オプティマイザーの働き ···················································································· 243
1.2.3
オプティマイザーの目的と機能 ········································································· 245
1.2.4
オプティマイザーの利点 ···················································································· 245
1.3
アクセス・パス・セレクション·············································································· 246
1.4
DBMS 製品の支援機能 ··················································································· 248
1.4.1
テーブル設計の検証 ························································································· 248
1.4.2
ORACLE における支援機能 ··········································································· 250
(1)
EXPLAIN ········································································································· 250
(2)
SQL 文におけるヒント機能 ··············································································· 252
1.4.3
SQL Server における支援機能 ······································································· 253
(1)
パフォーマンス・モニター ·················································································· 253
(2)
UPDATE STATISTICS ················································································· 253
1.4.4
DB2 における支援機能 ···················································································· 254
第 2 章 インデックス ······································································································· 256
2.1
インデックスの最適化 ······················································································· 256
2.2
インデックス定義フィールドに関する考察 ························································ 257
(1)
データ形式の変換が起きないようにする ························································· 258
(2)
比較の文字ストリングの長さを同じにする ······················································· 259
(3)
算術演算を含む WHERE 述部ではインデックスは使われない ···················· 260
(4)
同じフィールドに対する複数の不等号の指定は BETWEEN で表現する
··························································································································· 261
(5)
14
ワイルドカードを使用する場合の注意 ······························································ 261
(6)
IN が副照会に使われているとインデックスは使われない ····························· 263
(7)
結合(join)に関する考察 ··················································································· 263
(8)
複合フィールド・インデックスを作るときは,
あらかじめフィールドを隣接させておく ······························································ 265
(9)
更新が頻繁に発生するフィールドにはインデックスを付けない方がよい
(10)
インデックスを付けすぎると更新速度が落ちる ··············································· 265
··························································································································· 265
第 3 章 データベース設計の実際 ··············································································· 266
3.1
データベース設計の範囲 ·················································································· 266
3.2
データベース設計のポイント ············································································· 268
(1)
オプティマイザーの機能を把握する ································································· 269
(2)
データベース設計を綿密に行う ········································································ 269
(3)
設計変更に対処できる仕組みを作っておく······················································ 270
(4)
正規化と冗長化のバランスをはかる ································································ 271
(5)
実環境に近いデータでパフォーマンスを測定する ·········································· 273
(6)
「ナル値」を効果的に使用する ·········································································· 274
索 引 ································································································································· 277
15