Using the SQLite3 CLI

Introduction

The SQLite3 Command Line Interface (CLI) provides a powerful and lightweight way to interact with SQLite databases directly from your terminal. Whether you're creating, querying, or debugging databases, the SQLite3 CLI is a versatile tool for rapid prototyping and learning SQL.

In this guide, you’ll learn how to:

Running the SQLite3 CLI

Most systems come with SQLite3 pre-installed. To check if SQLite3 is available and start the CLI:

sqlite3
      

Once launched, you’ll see an interactive shell similar to this:


SQLite version 3.28.0 2019-04-15 14:49:49
Enter ".help" for usage hints.
sqlite>

      

This session creates a transient, in-memory database, which means any changes or data entered will be lost once you exit. To exit the CLI, press CTRL + D.

What if SQLite3 isn’t installed?

If the SQLite3 client doesn’t appear, you’ll need to install it. Visit the SQLite Downloads page and download the appropriate version for your operating system. Follow the installation instructions provided for your platform.

Opening a Database File

Unlike most relational database management systems (RDBMS), SQLite3 stores data in local files. To open or create a database file, use the following command:

sqlite3 example.db
      

This command does the following:

Naming Conventions

While SQLite3 supports any file extension, the following conventions improve readability and portability:

Appropriate Use Cases for SQLite3

SQLite3 is a lightweight, file-based database system that’s ideal for specific scenarios:

However, SQLite3 is not suitable for production environments due to its lack of robust security features. For example:

What You Learned

SQLite3’s simplicity and portability make it an excellent choice for learning SQL, prototyping applications, and testing database designs. However, always consider the trade-offs and choose the right tool for your project's needs.