SQLite Learning Note 3: Attaching a database and detaching a database

Source: Internet
Author: User

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.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.