SQLite

How to Show Databases in SQLite Command?

A database is a group of well-organized data that allows for efficient information storage, modification, and retrieval. SQLite is a database that manages data through queries and is popular in web development, mobile devices, and embedded systems. The sqlite3 is a command-line tool for interacting with SQLite databases using simple statements. With a few commands, you can build, edit, and display databases with simple commands.

We will provide step-by-step directions on how to display databases in SQLite command to help you through the process.

How to Show Databases in SQLite Command

To begin using SQLite, open your system’s command prompt and enter the following command to open SQLite interpreter:

sqlite3

To follow along with the examples in this guide, we will assume that you are executing all commands in the C:\sqlite\db path. However, feel free to choose your own path on your system.

To create an SQLite database named linux.db, execute the following command:

sqlite3 linux.db;

Note: The above command for creating a database is optional and is only necessary if you haven’t already created a database using the SQLite command.

To display all the databases of the current connection, run the following SQLite command:

.databases

This will show a list of all the databases attached to the current connection.

In the above screenshot, there is only one database linux.db in the path C:\sqlite\db. If you have multiple databases connected, they will be displayed here.

If you have created multiple databases and the above command does not list them, use the “attach database” command to add them to the current connection. This command connects to a new database and makes its tables available for use in SQL queries.

In the below-given command, I am creating a new database named linux2 in the same connection linux.db:

attach database "C:\sqlite\db\linux.db" as linux2;

You can add multiple databases using the above-given command:

Once the connection is established between these databases you can run the .databases command again to show the databases in SQLite:

Bottom Line

The sqlite3 is the command line tool for interacting with the SQLite databases. When using the command line tool, you can use the .databases command to show the connected databases. This command will return the list of databases with their location in the system.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.