Execute SQLite script

2019-01-31 11:20发布

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?

3条回答
在下西门庆
2楼-- · 2019-01-31 11:22

There are many ways to do this, one way is:

sqlite3 auction.db

Followed by:

sqlite> .read create.sql

In general, the SQLite project has really fantastic documentation! I know we often reach for Google before the docs, but in SQLite's case, the docs really are technical writing at its best. It's clean, clear, and concise.

查看更多
Ridiculous、
3楼-- · 2019-01-31 11:41

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.

查看更多
Bombasti
4楼-- · 2019-01-31 11:43

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

$ sqlite3 example.db 'SELECT * FROM some_table;'
查看更多
登录 后发表回答