sqlite3 コマンドでダンプしたファイルからDBを作成する

環境
Windows 11 Pro 64bit
sqlite 3.37.1

構文
.read ファイル名
ダンプしたファイルからDBを作成するには、「.read」でダンプした「ファイル」を指定します。

操作例
1.test.txt

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE testtbl(id integer,name text,age integer);
insert into testtbl values(1001,'tt',23);
insert into testtbl values(1002,'ss',43);
insert into testtbl values(1003,'sa',23);
insert into testtbl values(1004,'uu',63);
commit;
PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE testtbl(id integer,name text,age integer); insert into testtbl values(1001,'tt',23); insert into testtbl values(1002,'ss',43); insert into testtbl values(1003,'sa',23); insert into testtbl values(1004,'uu',63); 略 commit;
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE testtbl(id integer,name text,age integer);
insert into testtbl values(1001,'tt',23);
insert into testtbl values(1002,'ss',43); 
insert into testtbl values(1003,'sa',23);
insert into testtbl values(1004,'uu',63);
略
commit;

操作例
新しいDBを作成します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
C:\sqlite>sqlite3 test.sql
SQLite version 3.37.1 2022-12-30 15:30:28
Enter ".help" for usage hints.
sqlite> .table
sqlite> .read test.txt
sqlite> .table
C:\sqlite>sqlite3 test.sql SQLite version 3.37.1 2022-12-30 15:30:28 Enter ".help" for usage hints. sqlite> .table sqlite> .read test.txt sqlite> .table
C:\sqlite>sqlite3 test.sql
SQLite version 3.37.1 2022-12-30 15:30:28
Enter ".help" for usage hints.

sqlite> .table

sqlite> .read test.txt

sqlite> .table

 

 

SQLite

Posted by arkgame