How to open, view and query SQLite in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# How to open, view and query SQLite in VS Code

You can use an extension to open, view and query SQLite database files directly in Visual Studio Code.

To install the extension:

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux
    • Command + Shift + X on macOS
  1. Type SQLite and install the extension by alexcvzz.

install sqlite extension

  1. Click on the Install button.

# Opening an SQLite (.db) file directly in VS Code

Once you install the extension, you can open an SQLite file by:

  1. Right-clicking on the file in Explorer.

  2. Clicking on Open Database.

open database

  1. The database will appear as a collapsed menu in the Explorer tab.

click on sqlite explorer

  1. Click on SQLite Explorer to expand the database.

expand database menu and view database

  1. Once you expand the database view, you can click on a specific table and click on the arrow to view the table's data.

click to view table

You can also right-click on a table to show it or run a query.

right click show table

An alternative way to open the SQLite file is to:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type SQLite open and select SQLite: Open Database.

sqlite open database

Make sure to expand the SQLite Explorer menu in the left sidebar after you open the database.

expand database menu and view database

# Running SQLite queries directly in VS Code

To run a query, create a .sql file, for example, 001.sql and type a query.

The following code sample selects the first 10 rows from a table called albums.

001.sql
SELECT * FROM albums LIMIT 10;

select rows from table

To run the query:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type SQLite run query.

sqlite run query

  1. Click on the SQLite: Run Query option.

  2. You might get prompted to select your database.

select database

Once you run the query a new tab that contains the results will open.

run sqlite query success

There is also a shortcut for running a query:

  • Ctrl + Shift + Q on Windows and Linux.
  • Command + Shift + Q on macOS.

The window that contains the results enables you to:

  • View the SQL code that was run to generate the result.
  • Export the data as CSV, HTML or JSON.
  • Toggle the visibility of the data.
  • Paginate through the results.

view sql code or export as

# Closing the Database

Once you are done working with the database, you can close it by:

  1. Pressing:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
  1. Typing SQLite run query.

sqlite close database

  1. Clicking on the SQLite: Close Database button.

I've also written an article on how to view and edit Binary files in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.