The shell allows redirection, and sqlite3
can get the command as a parameter:
sqlite3 test.db .schema > schema.sql
or
sqlite3 test.db <<EOF .output schema.sql .schema EOF
For example, you can export only the schema of apple.db
to backup.sql
with .schema
as shown below.
sqlite3 apple.db .schema > backup.sql
And, you can export only the schema of apple.db
to backup.sql
with the commands below. *.output
creates and selects or only selects a file depending on the file existence and you must exit to close the file (e.g., .exit
or .quit
) otherwise the results of SQLite commands are output to the file:
sqlite3 apple.db sqlite> .output backup.sql sqlite> .schema sqlite> .exit
And, you can export only the schema of the specific tables in apple.db
to backup.sql
with the commands below. *.schema
exports the schema of only one specific table so you should run .schema
multiple times if you want to export the schema of the specific multiple tables:
sqlite3 apple.db sqlite> .output backup.sql sqlite> .schema person sqlite> .schema animal sqlite> .exit
932