sqlite メモ

SQLiteを使う機会も増えてきているので、メモ

コマンドラインではSQLiteのDBファイル名を指定

sqlite3 sample.db

データベース一覧

.databases

テーブル一覧

.tables

テーブル定義の表示

.schema ticket

コマンドラインからのSQL文実行には、次のようなファイルsample.sql を用意する。ここでは、タブ区切りで出力。

.mode tabs
select id, type, time, status, summary from ticket where status not in ('closed') order by id, status;

次のようにして実行。ここでは、Trac のDBの ticketのテーブルを検索している。

sqlite3 db/trac.db < sample.sql