I have .sql files which have the following content:
#cat db.sql
create table server(name varchar(50),ipaddress varchar(15),id init)
create table client(name varchar(50),ipaddress varchar(15),id init)
Run Code Online (Sandbox Code Playgroud)
How do I import this file into SQLite so that these are created automatically?
Dom*_*ger 146
从sqlite提示符:
sqlite> .read db.sql
Run Code Online (Sandbox Code Playgroud)
要么:
cat db.sql | sqlite3 database.db
Run Code Online (Sandbox Code Playgroud)
此外,您的SQL无效 - 您需要;在语句结束时:
create table server(name varchar(50),ipaddress varchar(15),id init);
create table client(name varchar(50),ipaddress varchar(15),id init);
Run Code Online (Sandbox Code Playgroud)
Eif*_*ion 54
使用sqlite3 database.sqlite3 < db.sql.您需要确保您的文件包含有效的SQLite SQL.
小智 14
或者,您可以从Windows命令行提示符/批处理文件执行此操作:
sqlite3.exe DB.db ".read db.sql"
Run Code Online (Sandbox Code Playgroud)
其中DB.db是数据库文件,db.sql是要运行/导入的SQL文件.
Ian*_*and 13
你也可以这样做:
sqlite3 database.db -init dump.sql
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116267 次 |
| 最近记录: |