In front of you. If you create a database, then we need to operate the database;
But the Sqlite3 command can only operate one database at a time, what if there are multiple databases under the current path? This will require the use of additional databases.
An associated database
Attaching a database is actually telling Sqlite3 that the SQL statement you wrote is the database you are working on. How does it work?
The basic syntax is as follows:
ATTACH DATABASE ' DatabaseName ' as ' alias-name ';
the statements in *sqlite3 need to be finished in a good minute.
Using the name above, if the database exists, it will be associated to ' alias-name '; if it does not exist, the ' DataBaseName ' will be created first and then associated.
So, we can use the following command to correlate to the database we created earlier:
sqlite> ATTACH DATABASE ' mydatabase.db ' as ' TEST ';
Use the command at this time:
. Database
You can see that I see one more ' test ' database, which is associated with the same file as our mydatabase.
#此时你还可以看到一个main数据库, the main or temp database cannot be used to correlate, otherwise an error will be made: Database main/temp is already on use.
Two separate databases
Separating and attaching is a reverse process, with the following basic syntax:
DETACH DATABASE ' Databasename-name ';
#无法分离main或者temp数据库
Separating the current data has no effect on other databases attached to the file.