SQLite script FAQ: How do I read/execute a CREATE TABLES
script from the SQLite command line? (How do I read or execute commands in a file from the sqlite3
command line?)
Background
Many times when you’re working with a SQLite database, you’ll keep all your CREATE TABLE
SQL commands in a database script, which you'll then execute from your database server command line prompt. The file of database commands you execute is often referred to as a "script", or in this case, a "SQLite script".
How to execute a SQLite script (file)
SQLite is no different, and assuming your CREATE TABLE
commands are in a file named create.sql, you can execute your script from the SQLite command line using the .read
command from inside your SQLite command shell, like this:
sqlite> .read create.sql
As the name of the command implies, this command reads your SQLite script/file and executes all of the command in it.
On a related note, if you need an example SQLite script to work with, please see my SQLite create table examples article.