2

I'm pretty sure there is a simple answer to this but I can't find it anywhere and can't seem to figure it out for myself.. Any help would be greatly appreciated.

I'm trying to copy a table from a .sql file (ex1.sql) that has a basic table in it. I can create this no problem but then I'm running the following to copy this table into a database (ex1.db):

sqlite3 ex1.db < ex1.sql

I'm getting the following response

C:\SQLite>sqlite3 ex1.db < ex1.sql onperson CREATE TABLE person (format 3) NB: smileyface symbol after "onperson"
first_name text,
last_name text,
age integer
)

It looks like the table is being replicated in the database or am I getting this wrong?

Anyway, when I then go back into the ex1.db there is no table there.

Any idea as to why this isn't saving? Do I need to add further commands to this to get it to save in the db file?

Apologies if this is a stupid question. Rather new to this.

Thanks!

3
  • What are the contents of ex1.sql? Where does this file come from? Commented Jun 11, 2013 at 17:11
  • I created it by doing the following: $ sqlite3 ex1.sql and then I created a table inside it which was: create table person (id integer primary key, first_name text, last_name text, age integer); for reference I'm following this guide: sql.learncodethehardway.org/book/ex1.html Commented Jun 11, 2013 at 17:29
  • 1
    I've figured this out.. I was creating the .sql file within SQLite3 rather than producing it in Notepad and importing it into the database that way. Apologies and thanks! Commented Jun 11, 2013 at 18:01

1 Answer 1

2

I ran into this exact problem, and I have never touched SQLite before. Here are more instructions for people in the future.

In a text editor, create ex1.sql. This is the file that will be used to create the .db when the command sqlite3 ex1.db < ex1.sql is run.

ex1.sql

CREATE TABLE person (
    id INTEGER PRIMARY KEY,
    first_name TEXT,
    last_name TEXT,
    age INTEGER
);

Make sure to save this file in the same folder as the sqlite3.exe file you downloaded. You can now run the aforementioned command and you are good to go!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.