Export the Schemas of Multiple Tables in a Database
The approach to export schema of multiple databases is not same as done above. We follows the below steps:
Step 1: Start the sqlite3 session on `gfg` database by typing sqlite3 gfg.db in our terminal. This opens an sqlite3 shell where we can write sqlite3 commands.
sqlite3 gfg.db
Step 2: Set the output of the commands to be written to a file instead of being displayed inside the shell. In this example, we are redirecting the output to be written to multiple_table_schema.sql file.
.output multiple_table_schema.sql
Step 3: Using the `sqlite_schema` table which stores the metadata of all the objects of our currently opened database.
We will export users and `courses` table schemas. Below command selects SQL(i.e. DDL) for multiple tables is as follows:
SELECT sql FROM sqlite_schema where type='table' and (name='users' or name='courses');
NOTE: The sqlite_schema table contains one row for each database object like tables, indexes, viewes, and triggers present within the schema.
Output:
How to Export Database and Table Schemas in SQLite?
Exporting database schemas in SQLite is an important task for database management, enabling functions like data backup, recovery, migration, and auditing.
In this article, We will go through the process of exporting database and table schemas in SQLite by understanding various examples to manage SQLite databases effectively.