rktSQLite

rktSQLite2




トランザクションの操作

BEGIN
トランザクションの開始
BEGIN [TRANSACTION [名前]] [ON CONFLICT 衝突時アルゴリズム] 
サンプル
カラムの追加。
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE prefecture_tbl_alter (
    id          integer,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl_alter SELECT *,0 AS group FROM prefecture_tbl;
DROP TABLE prefecture_tbl;
CREATE TEMPORARY TABLE prefecture_tbl (
    id          integer PRIMARY KEY,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl SELECT * FROM prefecture_tbl_alter;
END TRANSACTION;

END
トランザクションの終了
END [TRANSACTION [名前]] 

COMMIT
トランザクションの確証
COMMIT [TRANSACTION [名前]] 
サンプル
カラムの追加。
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE prefecture_tbl_alter (
    id          integer,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl_alter SELECT *,0 AS group FROM prefecture_tbl;
DROP TABLE prefecture_tbl;
CREATE TEMPORARY TABLE prefecture_tbl (
    id          integer PRIMARY KEY,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl SELECT * FROM prefecture_tbl_alter;
COMMIT;

ROLLBACK
トランザクションの内のクエリを取りやめる
ROLLBACK [TRANSACTION [名前]] 
サンプル
カラムの追加。
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE prefecture_tbl_alter (
    id          integer,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl_alter SELECT *,0 AS group FROM prefecture_tbl;
DROP TABLE prefecture_tbl;
CREATE TEMPORARY TABLE prefecture_tbl (
    id          integer PRIMARY KEY,
    name        integer,
    group       integer
);
INSERT INTO prefecture_tbl SELECT * FROM prefecture_tbl_alter;
ROLLBACK;