开发者

How do I import .sql files into SQLite 3?

开发者 https://www.devze.com 2022-12-16 17:05 出处:网络
I have .sql files which have the following content: #ca开发者_JAVA百科t db.sql create table server(name varchar(50),ipaddress varchar(15),id init)

I have .sql files which have the following content:

#ca开发者_JAVA百科t db.sql
create table server(name varchar(50),ipaddress varchar(15),id init)
create table client(name varchar(50),ipaddress varchar(15),id init)

How do I import this file into SQLite so that these are created automatically?


From a sqlite prompt:

sqlite> .read db.sql

Or:

cat db.sql | sqlite3 database.db

Also, your SQL is invalid - you need ; on the end of your statements:

create table server(name varchar(50),ipaddress varchar(15),id init);
create table client(name varchar(50),ipaddress varchar(15),id init);


Use sqlite3 database.sqlite3 < db.sql. You'll need to make sure that your files contain valid SQL for SQLite.


Alternatively, you can do this from a Windows commandline prompt/batch file:

sqlite3.exe DB.db ".read db.sql"

Where DB.db is the database file, and db.sql is the SQL file to run/import.


You can also do:

sqlite3 database.db -init dump.sql
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号