As a beginning programmer with +20 hours of Python coding and novice familiarity with the command-line, I opened up Zed Shaw\'s \"Learn SQL The Hard Way\" and was quickly st
I ran into same problem today, and like you I was wondering why my command is not working. As mentioned above author assumes that you create the initial command in a text editor and save as a .sql file. And then ex1.db < ex1.sql command converts the file to a .db file.
sqlite3 ex1.db < ex1.sql
For the above to work, ex1.sql
should already exist. <
is a character used in shells for input redirection. sqlite3
is started here with a new or existing database (it will create the database as needed), and gets SQL statements from ex1.sql
, executing them and modifying ex1.db
accordingly.
Now let's generate ex1.sql
from ex1.db
, which you apparently want to do:
sqlite3 ex1.db .dump > ex1.sql
We use shell redirection facility again, now redirecting the output to ex1.sql
. The .dump
command makes sqlite
write out SQL statements that will recreate similar database when they are executed in an empty database: tables are recreated and populated with INSERT
, etc.
Now you can go to step 1:
sqlite3 ex1copy.db < ex1.sql