参考サイト
データベース作成
sqlite3 hoge.db
で、hoge.dbがなかったら作られる。
sqliteコマンドライン
終了
.exit
テーブル名表示
.tables
データ表示
.dump テーブル名
スキーマ表示(どう作ったか)
.schema テーブル名
バックアップファイルを作る
.backup ファイル名
バックアップファイルからDBを復元する
.restore ファイル名
データの表示の仕方を変える
.mode
csv,column,html,insert,line,list,tabs,tcl
テーブル作成
create table テーブル名 (変数名 型 オプション,変数名 型 オプション,...);
型
INTEGER,DATETIME,TEXT
オプション
PRIMARY KEY
NOT NULL
データ挿入
BEGIN TRANSACTION;
insert into テーブル名 values (3,2,4,'popoi');
COMMIT;
属性の指定での挿入
BEGIN TRANSACTION;
insert into (変数名,変数名) values ('poipoi',3);
COMMIT;
選択表示
select * from テーブル名;
選択をビューとして保存
create view hogeView as select * from テーブル名;
並び順
select * from テーブル名 order by age;
結果の3から5番目
select * from テーブル名 limit 5 offset 3;
検索条件つき
select * from テーブル名 where age > 20 or age < 5;
更新
update テーブル名 set name = 'poi',age = 20 where id = 5;
削除
delete from テーブル名 where id = 10;
Rubyで用いる
最終更新:2011年12月26日 15:04