| sql-statement ::= | ATTACH [DATABASE] database-filename AS database-name |
The ATTACH DATABASE statement adds a preexisting database file to the current database connection. If the filename contains punctuation characters it must be quoted. The names 'main' and 'temp' refer to the main database and the database used for temporary tables. These cannot be detached. Attached databases are removed using the DETACH DATABASE statement.
You can read from and write to an attached database, but you cannot alter the schema of an attached database. You can only CREATE and DROP in the original database.
You cannot create a new table with the same name as a table in an attached database, but you can attach a database which contains tables whose names are duplicates of tables in the main database. It is also permissible to attach the same database file multiple times.
Tables in an attached database can be referred to using the syntax database-name.table-name. If an attached table doesn't have a duplicate table name in the main database, it doesn't require a database name prefix. When a database is attached, all of its tables which don't have duplicate names become the 'default' table of that name. Any tables of that name attached afterwards require the table prefix. If the 'default' table of a given name is detached, then the last table of that name attached becomes the new default.
When there are attached databases, transactions are not atomic. Transactions continue to be atomic within each individual database file. But if your machine crashes in the middle of a COMMIT where you have updated two or more database files, some of those files might get the changes where others might not.
There is a compile-time limit of 10 attached database files.
Executing a BEGIN TRANSACTION statement locks all database files, so this feature cannot (currently) be used to increase concurrancy.
| sql-command ::= | DETACH [DATABASE] database-name |
This statement detaches an additional database connection previously attached using the ATTACH DATABASE statement. It is possible to have the same database file attached multiple times using different names, and detaching one connection to a file will leave the others intact.
This statement will fail if eSQL is in the middle of a transaction.