URL:
http://www.db.is.kyushu-u.ac.jp/rinkou/addb/5.html
解凍すると sqlite3_analyzer.exe ができる.
「Sqliteman」 のアイコンをダブルクリック (double click "Sqliteman.exe")
Sqliteman のウインドウが開く.(A New window appears)
「File」→ 「Exit」で終了.
以下の手順で,既存のデータベース「C:\SQLite\mydb」を開く. (Open an existing database 'C:\SQlite\mydb')
まず,「Pragmas」をクリック.(Click 'Pragmas')
encodingの行に「UTF-8」のように表示されている.
※ もし,データベースの文字のエンコーディングを変えたいときは, Sqliteman のようなグラフィカルなツールを使うのではなく, sqlite.exe を起動し「PRAGMA encoding=...;」で変える方がずっと簡単でしょう. 例えば「UTF-16le」などに変えたいなど.
SQL を用いて,products テーブルを定義し,一貫性制約を記述する. (Define 'products' table and specify integrity constrants of the table using SQL)
リレーショナル・スキーマ (relational schema): reports(id, docid, path, val, created_at)
次の SQL を入力し,「Run SQL」のアイコンをクリック (Write the following SQL, and click "Run SQL" icon).
CREATE TABLE reports ( id INTEGER PRIMARY KEY AUTOINCREMENT NULL, docid INTEGER NOT NULL, path TEXT NOT NULL, val TEXT NOT NULL, created_at DATETIME NOT NULL );
※ 「SQL Editor」のウインドウには,SQL プログラムを書くことができる. In the 'SQL string' window, you can write down SQL program(s).
エラーメッセージが出ていないことを確認
次のような reports テーブルを作る. (Construct table 'reports')
以下の手順で,SQL を用いて reports テーブルへの行の挿入を行う (Insert rows into table 'reports' using SQL)
BEGIN TRANSACTION; INSERT INTO reports VALUES( 1, 1, '/root/title', 'report A', datetime('now') ); INSERT INTO reports VALUES( 2, 1, '/root/author', 'kaneko', datetime('now') ); INSERT INTO reports VALUES( 3, 1, '/root/date', '2009/11/29', datetime('now') ); COMMIT;
複数の SQL 文を一括実行したいので,カーソルを先頭行に移動した後に, 「Move the cursor to the top statement. Click "Run multiple SQL statements from current cursor position in one batch" icon)
エラーメッセージが出ていないことを確認
まず,オブジェクト・ブラウザ (Object Browser) の中の「Tables」を展開 (Click 'Tables')
次に,テーブル reportsを選ぶ (Select table 'reports')
テーブル reportsが表示される (table 'reports' appears)
※ もし,データに間違いがあれば,このウインドウで修正できる (If you find any mistakes, you can modify the data using this window).
reports テーブルのルート・ページ番号が分かる.この場合は「23」になっているが,違う値になっていても問題はない. (The root page number of table 'reports'. In this figure, the number is '23').
ルート・ページ番号は,データベース管理システムが自動的に決める番号である.
このときデータベースが保存される (Database is saved automatically)
データベースファイルは,レコードを単位とした物理構造になっている.
This figure is from the 'SQLite Database File Format' Web page. http://www.sqlite.org/fileformat.html
records テーブルのルート・ページ番号が 23 の場合:
データベース・ファイルのデータページの中には,レコードが並んでいることが確認できる.データページの中には未使用部分がある.
There a sequence of records in data pages in database file.
この演習では docid フィールドは無視する.整数データはコード化されている.数値データのコード化体系はデータベース管理システムの種類によって違う. In this exercise, ignore the 'docid' field. The integer value is encoded.
SQLite データベース・ディレクトリ C:\SQLite に移る.
C: cd C:\SQLite
このとき,データベース論理名として mydb を指定する.(The logical database name is 'mydb').
データベースの情報はファイル dbinfo.sql に格納する.このファイル名はなんでも良いが、アルファベットのみを使うのが良い.
.\sqlite3_analyzer.exe mydb > dbinfo.sql
このとき,データベース論理名として mydb を指定する.(The logical database name is 'mydb').
.\sqlite3.exe mydb
.read dbinfo.sql
「.exit」で終了.
「Sqliteman」 のアイコンをダブルクリック (double click "Sqliteman.exe")
Sqliteman のウインドウが開く.(A New window appears)
データベースの情報が表示される
int_pages, leaf_pages, ovfl_pages の列は,は各テーブルが占有しているページの数を示している. (Number of pages which each table occupies)
次の問いに答えよ. Answer the following questions.
問い (Questions)
次の PTABLE テーブルに関する問題 (About the following 'PTABLE' table)
name | type | color ------------------------------ apple | fruit | red apple | fruit | blue rose | flower | white rose | flower | red rose | flower | yellow
SQL を用いて PTABLE のテーブル定義を書きなさい (Write the table defintion of the table PTABLE using SQL)
SQL を用いて属性 name の二次索引を生成しなさい (Write a SQL to generate a secondary index on the attribute 'name')