対話モード
【対話モードに入る】 shell> sqlite3 データベース名 【対話モードから出る】以下3つ、いずれでもOK sqlite> .q sqlite> .quit sqlite> .exit
非対話モード
【非対話モード】 shell> sqlite3 オプション データベース名 "操作文"
-init ファイル名-echo-header-noheader-column-html-line-list-separator 区切り文字【例】sqlite3 -separator , log.db 'select * from main_tbl'
-nullvalue 文字-version-help.mode).output)create table)drop table).schema)insert into)select)update)delete from).read)【書式】 sqlite> .mode 出力モード;
【書式1】ファイルに出力 sqlite> .output 出力先ファイル名; 【書式2】標準出力(画面)に出力 sqlite> .output stdout;
【書式】 sqlite3 データベース名 【例】 shell> sqlite3 test.db SQLite version 3.6.10 Enter ".help" for instructions sqlite> .quit shell>
【書式】 create table テーブル名 (カラム名 型, カラム名 型...); 【例】 shell> sqlite3 test.db SQLite version 3.6.10 Enter ".help" for instructions sqlite> create table tbl1 ...> (id INT, name VARCHAR(30),bd DATE); sqlite> .quit shell>
なお、対話モードに入らず直接操作することもできる。
shell> sqlite3 test.db "create table tbl1 (id INT, name VARCHAR(30), bd DATE);"
【書式】 DROP TABLE IF EXIST データベース名.テーブル名 【例】 shell> sqlite3 test.db SQLite version 3.6.10 Enter ".help" for instructions sqlite> .schema tbl1 CREATE TABLE tbl1 (id INT, name VARCHAR(30), bd DATE); sqlite> drop table tbl1 shell>
参考文献・サイト
【書式】 .schema テーブル名 【例】 shell> sqlite3 test.db SQLite version 3.6.10 Enter ".help" for instructions sqlite> .schema tbl1 CREATE TABLE tbl1 (id INT, name VARCHAR(30), bd DATE); sqlite> .quit shell>
【書式】 insert into テーブル名 (カラム名...) values (データ...); 【例】 shell> sqlite3 test.db "insert into tbl1 (id, name, bd) values (1,"Jack",2008/1/1);"
【書式】 UPDATE テーブル名 SET カラム名='値',カラム名='値',... WHERE 条件 【例】
【書式】 delete from テーブル名 条件節 【例】test.db の main テーブルからカラムdateが'2010/03/01'のデータ(レコード、行)を削除する。 shell> sqlite3 test.db "delete from main where date='2010/03/01';"
【書式】 .read ファイル名 【例】 shell> sqlite3 test.db sqlite3> .mode csv ←出力モードをcsvにする sqlite3> .output test.csv ←出力先ファイルをtest.csvに設定 sqlite3> .read test.sql ←test.sqlに書かれたsql文を実行して設定したファイル(test.csv)に出力
| 型 | 書式 | 内容 |
|---|---|---|
| NULL型 | NULL | |
| 整数型 | INT | 符号付き整数、値の大きさに応じて1,2,3,4,6,8バイトをとる |
| 実数型 | REAL | 浮動小数点値、8バイトをとる |
| テキスト型 | TEXT | テキスト文字列。データベースのエンコードで保存される(UTF-8など)。 |
| バイナリ型 | BLOB | バイナリデータ。データはそのままの状態で保存される。 |
参考文献・サイト: