You can use the SQLite .clone
dot command to create a clone of the current database.
The way it works is quite simple. You simply use .clone newdb
where newdb
is the name of the new database you want created.
Example
Here’s an example to demonstrate.
First, I’ll connect to SQLite and specify a database to use:
sqlite3 Store.db
Once connected, I can run the following code to clone that database:
.clone Store2.db
In this case, I clone the Store.db database to a file called Store2.db.
When you run this, you’ll probably see messages written to the console as each table gets cloned.
Like this:
sqlite> .clone Store2.db Customers... done Products... done Orders... done
Clone Another Database
If you use .open
to open another database, you can clone that one too.
Here, I open the Chinook sample database, then immediately clone it.
.open Chinook.db
.clone Chinook2.db
Output to the console:
Album... done Artist... done Customer... done Employee... done Genre... done Invoice... done InvoiceLine... done MediaType... done Playlist... done PlaylistTrack... done Track... done IFK_AlbumArtistId... done sqlite_autoindex_PlaylistTrack_1... done IFK_CustomerSupportRepId... done IFK_EmployeeReportsTo... done IFK_InvoiceCustomerId... done IFK_InvoiceLineInvoiceId... done IFK_InvoiceLineTrackId... done IFK_PlaylistTrackTrackId... done IFK_TrackAlbumId... done IFK_TrackGenreId... done IFK_TrackMediaTypeId... done