tags:

views:

180

answers:

2

I have .sql files which has following contents :

#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)

How to import this file into sqlite ?So that these are created automatically? Thanks.

+2  A: 

Have you tried sqlite3 database.sqlite3 < db.sql? You'll need to make sure that your files contain valid SQL for sqlite.

Eifion
thanks Eifion!! for your soultion its works fine too.
lakshmipathi
+4  A: 

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);
Dominic Rodger
sqlite3 DB.db < db.sql Error: incomplete SQL: create table server(name varchar(50),ipaddress varchar(15),id init) create table client(name varchar(50),ipaddress varchar(15),id init) what's this error mean? I tried both methods >.read db.sql and sqlite3 DB.db < db.sql...Thanks
lakshmipathi
thanks It's working now. I missed out ; and included invalid chars like "-". Now it's fine.Thanks !!!
lakshmipathi
@lakshmipathi, if it's working you can mark one of the two answers that answered your question as accepted by clicking the tick under the vote count next to the answer.
Dominic Rodger
yes...it's done now..
lakshmipathi