/    /  SQLiteDB – Attach DB

SQLiteDB – Attach DB:

You created multiple databases in SQLite and how to connect only the database you want. That can be achieved by using the command attach database

Syntax:Attach Database 'databasename.db' as aliasname;

Example:

Let’s first connect to SQLite, and check the current database you are in.

[root@tuto~]# sqlite3

SQLite version 3.3.6

Enter ".help" for instructions

sqlite> .databases

seq  name             file                                                     

---  ---------------  ----------------------------------------------------------

0    main

Give the command to connect to custDB.db database with alias name as customer.

[root@tuto~]# sqlite3

SQLite version 3.3.6

Enter ".help" for instructions

sqlite> attach database 'custDB.db' as customer;

Now verify the database you connected.

sqlite> .database

seq  name             file                                                     

---  ---------------  ----------------------------------------------------------

0    main                                                                      

2    customer         /root/custDB.db

Note:

Please do not use the main and temp as alias database names as they reserved.