SQLite は,パブリックドメインの組み込み型のデータベース管理システム・ソフトウエアです.
この Web ページでは,SQLite 3 コマンドライン・インタフェースのダウンロードと実行を行う. SQLite 3 コマンドライン・インタフェースの中にすでに データベース管理システムが組み込まている.
SQLite の利点を大胆にまとめると,
のことを考えなくても使える.通信しないので,ファイヤウオールの設定で悩むこともない.以上が利点である.
SQLite の SQL に関する詳しい説明は:
SQLite コマンドライン・クライアントに関する詳しい説明は:
■ Ubuntu での実行手順例
sudo apt -yV install sqlite3
Linux の端末 (terminal) で,次の操作を行う.
このとき,データベース名として /var/tmp/mydb を指定する.SQLite の流儀で,データベース名はファイル名になる.
※ データベース名はなんでも良いが、英文字と数字のみを使うのが良い.
※ データベース名は「../hoge」のような相対パス形式でもいいし,カレントディレクトリを使うつもりで「hoge2」のようにしてもいい.
sqlite3 /var/tmp/mydb
「.help」で,ヘルプが表示される.
.help
「PRAGMA encoding;」で,エンコーディングが表示される.
PRAGMA encoding;
「.exit」で終了.
.exit
ここでの設定
sqlite3
空のデータベースを作成したいので次のように操作.
「--new 」を付けているので,すでにデータベースファイルが存在するときは,その中身を空にする.
.open --new /var/tmp/hoge.db
.exit
ここで定義するテーブル: P(id, name, weight)
sqlite3
空のデータベースを作成したいので次のように操作.
「--new 」を付けているので,すでにデータベースファイルが存在するときは,その中身を空にする.
.open --new /var/tmp/hoge.db
create table order_records (
id integer primary key not null,
year integer not null CHECK ( year > 2008 ),
month integer not null CHECK ( month >= 1 AND month <= 12 ),
day integer not null CHECK ( day >= 1 AND day <= 31 ),
customer_name text not null,
product_name text not null,
unit_price real not null check ( unit_price > 0 ),
qty integer not null default 1 check ( qty > 0 ),
created_at timestamp not null default (datetime('now', 'localtime')),
updated_at timestamp not null default (datetime('now', 'localtime')),
check ( ( unit_price * qty ) < 200000 ) );
create trigger order_records_update after update on order_records
begin
update order_records set last_updated_at = (datetime('now', 'localtime')) where id = new.id;
end;
begin transaction; insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 1, 2020, 7, 26, 'kaneko', 'orange A', 1.2, 10 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 2, 2020, 7, 26, 'miyamoto', 'Apple M', 2.5, 2 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 3, 2020, 7, 27, 'kaneko', 'orange B', 1.2, 8 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price) values( 4, 2020, 7, 28, 'miyamoto', 'Apple L', 3 ); commit;
select * from order_records;
begin transaction; update order_records set unit_price = 11.2 where id = 1; commit; select * from order_records;
.tables
.exit
本サイトは金子邦彦研究室のWebページです.サイトマップは,サイトマップのページをご覧下さい. 本サイト内の検索は,サイト内検索のページをご利用下さい.
問い合わせ先: 金子邦彦(かねこ くにひこ) ![]()