HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Imagine a situation, when there is more than one database at the same time is available, you want to use any of them. The SQLiteATTACH DTABASE statement is used to select a specific database, use this command after all SQLite statement will be executed in the attached database.
The basic syntax of SQLite ATTACH DATABASE statement is as follows:
ATTACH DATABASE 'DatabaseName' As 'Alias-Name';
If the database has not been created, the above command will create a database if the database already exists, put the database file name and the logical database 'Alias-Name' to bind together.
If you want to attach to an existing databasetestDB.db, the ATTACH DATABASE statement is as follows:
sqlite> ATTACH DATABASE 'testDB.db' as 'TEST';
UseSQLite .database command to display the additional database.
sqlite> .database seq name file --- --------------- ---------------------- 0 main /home/sqlite/testDB.db 2 test /home/sqlite/testDB.db
Main and tempdatabase name is reserved for the primary database and the database stores temporary tables and other temporary data objects. These two databases are available for each database connection name, and should not be used for additional, or they will get a warning message, as follows:
sqlite> ATTACH DATABASE 'testDB.db' as 'TEMP'; Error: database TEMP is already in use sqlite> ATTACH DATABASE 'testDB.db' as 'main'; Error: database TEMP is already in use