SQLite ATTACH DATABASE
ATTACH DATABASE
ATTACH DATABASE adds another database to the current connection. You give it a schema name, and use the name in front of the table names, like archive.OldOrders.
ATTACH DATABASE 'file_name' AS schema_name;
Example
This example attaches a new database in memory with the name "archive", and copies the orders from July 1996 into a table in it:
Example
ATTACH DATABASE ':memory:' AS archive;
CREATE TABLE archive.OldOrders AS
SELECT * FROM Orders
WHERE OrderDate < '1996-08-01';
SELECT * FROM archive.OldOrders;
Try it Yourself »
On your own computer, you write a file name instead of :memory:, like ATTACH DATABASE 'archive.db' AS archive;.
main and temp
Every connection has a database named main, for the file you opened. Temporary tables go into a database named temp. PRAGMA database_list lists the databases in the connection:
DETACH DATABASE
DETACH DATABASE removes an attached database from the connection:
DETACH DATABASE schema_name;