SQLite Attach Database

What is Attach database?

Assume a condition where you have multiple databases available and you have to use only one of them at a time. That's why ATTACH DATABASE statement is used. It facilitates you to select a particular database and after using this command, all SQLite statements will be executed under the attached database.

Syntax:

snippet
ATTACH DATABASE 'DatabaseName' As 'Alias-Name';
Note
Note: The above syntax will also create a database if the database is not already present, otherwise it will only attach a database file name with the logical database Alias-Name.

Let's take an example. We have an existing database JTP.db.

Example:

snippet
ATTACH DATABASE 'JTP.db' as 'JavaTpoint';
Sqlite Attach database 1

Database is attached now you can see it by using .databases command:

Sqlite Attach database 2
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents