1.8. SQLite attached database

发布时间 : 2025-10-25 13:32:42 UTC      

Page Views: 9 views

Suppose that when multiple databases are available at the same time, you want to use any of them. SQLite’s ATTACH DATABASE Statement is used to select a specific database, and after using this command, all SQLite statements will be executed under the attached database.

1.8.1. Grammar

The basic syntax of the ATTACH DATABASE statement for SQLite is as follows:

ATTACH DATABASE file_name AS database_name; 

If the database has not been created, the above command creates a database, and if the database already exists, bind the database file name to the logical database ‘Alias-Name’.

The open database and the database attached using ATTACH must be in the same folder.

1.8.2. Example

If you want to attach an existing database testDB.db The ATTACH DATABASE statement will look like this

sqlite> ATTACH DATABASE 'testDB.db' as 'TEST'; 

Use SQLite .database Command to display additional databases.

sqlite> .database seq name file --- --------------- ---------------------- 0 main /home/sqlite/testDB.db 2 test /home/sqlite/testDB.db 

Database name main And temp Is reserved for the master database and the database that stores temporary tables and other temporary data objects. These two database names can be used for each database connection and should not be used for attachment, otherwise you will get a warning message, as shown below:

sqlite> ATTACH DATABASE 'testDB.db' as 'TEMP'; Error: database TEMP is already in use sqlite> ATTACH DATABASE 'testDB.db' as 'main'; Error: database main is already in use; 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。