[sqlite] Execute SQLite script

I start up sqlite3 version 3.7.7, unix 11.4.2 using this command:

sqlite3 auction.db

where auction.db has not already been created.

sqlite> auction.db < create.sql;

gives me this error: near "auction": syntax error

How can I run the script?

This question is related to sqlite

The answer is


In order to execute simple queries and return to my shell script, I think this works well:

$ sqlite3 example.db 'SELECT * FROM some_table;'

If you are using the windows CMD you can use this command to create a database using sqlite3

C:\sqlite3.exe DBNAME.db ".read DBSCRIPT.sql"

If you haven't a database with that name sqlite3 will create one, and if you already have one, it will run it anyways but with the "TABLENAME already exists" error, I think you can also use this command to change an already existing database (but im not sure)


You want to feed the create.sql into sqlite3 from the shell, not from inside SQLite itself:

$ sqlite3 auction.db < create.sql

SQLite's version of SQL doesn't understand < for files, your shell does.


For those using PowerShell

PS C:\> Get-Content create.sql -Raw | sqlite3 auction.db