- Why SQLite?
- SQLite Data Types
- Prerequisites
- Connecting Database Client to Any Database
- Step 1: Create Database and Connect in Database Client
- Step 2: Create Tables Using .sql Script
- Step 3: Populate Tables Using .sql Script
- Step 4: Verify the Data
- Step 5: Execute Sample Practice Queries
- Option 2: Using SQLite Extension Plugin
- Running SQL in Jupyter Notebooks
- Database Schema
- Summary
Working with SQLite & Database Setup
In this guide, you will learn the fundamentals of SQLite, its data types, and how to set up, connect, and populate a local database in VS Code using the Database Client extension — a universal tool that allows you to connect to and manage SQLite, PostgreSQL, MySQL, and any other database.Interactive Jupyter Practice Notebook
Jupyter Execution Guide
Why SQLite?
SQLite is a software library that provides a lightweight, serverless relational database management system (RDBMS). Unlike traditional databases like PostgreSQL or MySQL, SQLite does not run as a separate server process. Instead, it reads and writes data directly to a single file on your computer’s disk.Features of SQLite
- Serverless: It does not require a separate server background process. The database engine runs inside the application process.
- Self-Contained: A single database is stored entirely in a single cross-platform file.
- Zero Configuration: There is no setup or administration needed. You just create a file and start using it.
- Transactional (ACID): Even though it is lightweight, it fully supports ACID properties (Atomicity, Consistency, Isolation, Durability) to ensure data safety.
Advantages
- Simple to use: Perfect for learning SQL, prototyping applications, and local development.
- Highly Portable: You can copy, share, or email the database file easily.
- Fast and Lightweight: Highly optimized code that runs fast and takes up very little memory.
- Widely Adopted: It is the most deployed database engine in the world, used in web browsers (Chrome, Firefox), mobile phones (Android, iOS), and many desktop applications.
Limitations
- Concurrency Issues: SQLite locks the entire database file during writes, meaning it is not suitable for high-write concurrency applications.
- Not suited for Big Data: While it can handle up to 281 TB database sizes in theory, it is not optimized for massive multi-terabyte enterprise datasets.
- No User Management: It does not support native user roles, permissions, or access control. Anyone with read/write access to the file can modify the database.
SQLite Data Types
Unlike other relational databases, SQLite has a dynamic type system. It supports the following storage classes (data types):Common Examples
Prerequisites
To work with databases directly inside Visual Studio Code, install either of these extensions:-
Database Client (by cweijan) — ⭐ Primary / Recommended Universal Tool
- Universal database manager for SQLite, PostgreSQL, MySQL, MariaDB, SQL Server, Redis, MongoDB, Snowflake, DuckDB, etc.
- Built-in visual data grid, SQL query editor with auto-completion, ER diagram generator, mock data generator, and export tools (CSV/JSON/SQL).
- Manages a dedicated
Queryfolder in your project structure for your.sqlfiles.
-
SQLite (by Alex Covizzi) — Alternative Lightweight Option
- Simple extension specifically for opening
.dbfiles and running queries.
- Simple extension specifically for opening
Connecting Database Client to Any Database
The Database Client extension turns VS Code into a universal database IDE. Whether you are using a local SQLite file or a remote database server, the workflow is consistent.1. Supported Databases
2. The Query Folder in Project Structure
When you work with Database Client, SQL query scripts are organized directly in your project structure under a Query folder (or .dbclient folder):
3. Connecting to External Databases (PostgreSQL, MySQL, etc.)
To connect to any database server:- Click the Database (cylinder) icon in the VS Code Activity Bar (left sidebar).
- Click
+(Create Connection) select your database engine (e.g. PostgreSQL or MySQL). - Enter your connection credentials:
- Host:
localhost(or cloud endpoint) - Port:
5432(PostgreSQL) /3306(MySQL) - Username:
postgres/root - Password:
<your-password> - Database:
<database_name>
- Host:
- Click Test Connection, then click Connect.
Step 1: Create Database and Connect in Database Client
- Create a new empty database file in your workspace root directory named:
- Open the Database Client panel by clicking the Database (cylinder) icon in the VS Code Activity Bar (left sidebar).
- Click the
+(Create Connection) button at the top of the panel. - Select SQLite from the database list.
- Enter the connection settings:
- Connection Name:
Employee DB - Database Path / File: Click the Browse / File Picker icon and select
employee.db(or type./employee.db).
- Connection Name:
- Click Connect (or Save).
Step 2: Create Tables Using .sql Script
- Create a new SQL script file in your workspace directory (or inside your
Query/folder) named:
- Open
setup.sqland paste the table definition DDL statements:
- Execute in Database Client:
- In VS Code with
setup.sqlopen, make sureEmployee DBis selected in the Database Client toolbar or status bar. - Highlight the
CREATE TABLEstatements. - Press
Cmd + Enter(macOS) orCtrl + Enter(Windows/Linux), or click the green Run / Execute button in the query toolbar.
- In VS Code with
- Click the Refresh icon in the Database Client panel. You will now see
departmentsandemployeeslisted under the Tables folder!
[!IMPORTANT] Executing Selected Queries: Always highlight/select the specific SQL statements you want to run before executing (Cmd+Enter/Ctrl+Enter). Running the whole script again after tables are created will result in a “table already exists” error.
Step 3: Populate Tables Using .sql Script
Append the followingINSERT INTO statements to your setup.sql file (or Query/setup.sql):
Department Data
Employee Data
Note:Gopal Krishnahas aNULLdepartment to demonstrateLEFT JOINandIS NULLqueries.
Execute in Database Client:
- Highlight the
INSERT INTOstatements. - Press
Cmd + Enter(macOS) orCtrl + Enter(Windows/Linux) to run the insertion. - In the Database Client sidebar, double-click the
employeestable to open the interactive data grid and view all 25 rows populated live!
Step 4: Verify the Data
Method 1: Using Database Client Interactive Data Grid (Fastest)
Double-click on thedepartments or employees table in the Database Client sidebar. An interactive spreadsheet view will open displaying all columns, rows, and data types.
Method 2: Running Verification Queries in SQL Console
Run the following queries in the Database Client SQL editor by highlighting and pressingCmd + Enter / Ctrl + Enter:
Display all departments:
Step 5: Execute Sample Practice Queries
Execute the following queries in the Database Client SQL editor (Cmd + Enter / Ctrl + Enter):
1. Display all employee names
2. Display employees from Hyderabad
3. Display employees with salaries greater than ₹70,000
4. Display employees sorted by salary descending
5. Display employee names with their department names (INNER JOIN)
6. Display all employees including those without a department (LEFT JOIN)
Advanced Database Client Features:
- 📊 Column Sorting & Filtering: Click on any column header in the result grid to sort ascending/descending or filter by values.
- 🗺️ Visual ER Diagram (ERD): Right-click
Employee DBin the sidebar and choose Visual Relationship (ERD) to view relationships betweendepartmentsandemployees. - 📤 Export Results: Right-click the result table or any table in the sidebar to export data into CSV, JSON, or executable SQL INSERT scripts.
Option 2: Using SQLite Extension Plugin
If you prefer a lightweight, SQLite-specific tool instead of the universal Database Client, you can use the SQLite extension by Alex Covizzi.Step 1: Install the Extension
- Open the Extensions view (
Ctrl + Shift + Xon Windows/Linux orCmd + Shift + Xon macOS). - Search for
SQLiteby Alex Covizzi and click Install.
Step 2: Open Your Database
- Open the Command Palette:
- Windows/Linux:
Ctrl + Shift + P - macOS:
Cmd + Shift + P
- Windows/Linux:
- Search for and select:
SQLite: Open Database. - Choose
employee.dbfrom your workspace directory. - An SQLITE EXPLORER section will appear in your VS Code Explorer sidebar showing the database and its tables.
Step 3: Run Queries from .sql Files
- Open
setup.sqlin VS Code. - Select/highlight any query (or block of queries) you wish to run.
- Right-click anywhere in the editor and choose Run Query (or press
Cmd + Shift + Q/Ctrl + Shift + Q). - When prompted, select
employee.db. - The query results will appear in a separate SQLite Results panel in VS Code.
Step 4: Browse Tables & Records
- In the SQLITE EXPLORER panel in the Explorer sidebar, expand
employee.dbto see all tables (departments,employees). - Click the play / show table icon next to any table to view all its records instantly.
Running SQL in Jupyter Notebooks
If you prefer using Jupyter Notebooks (.ipynb) instead of .sql files in VS Code, you can run SQL queries directly inside notebook cells using two different approaches.
Approach 1: Using %sql Cell Magics (ipython-sql)
ipython-sql allows you to write raw SQL directly inside Jupyter Notebook cells using %sql (single line) and %%sql (entire cell).
Step 1: Install Required Packages & Versions
Run this in your terminal or virtual environment:[!NOTE]prettytable<3.12prevents compatibility issues when rendering tabular SQL results withipython-sql.
Step 2: Load Extension & Connect to Database
In your Jupyter Notebook cell, load the extension and connect toemployee.db:
Step 3: Run Single-Line SQL Queries (%sql)
Step 4: Run Multi-Line SQL Queries (%%sql)
Use %%sql at the very top of a notebook cell to write multi-line SQL queries:
Step 5: Convert Query Result to Pandas DataFrame
Approach 2: Using Python sqlite3 + pandas
You can also use Python’s built-in sqlite3 module combined with pandas to execute queries and display clean DataFrame outputs without installing magic extensions.
[!TIP] Which approach should you use?
- Use Approach 1 (
%%sqlmagic) for quick, interactive SQL exploration directly in notebook cells.- Use Approach 2 (
sqlite3+pandas) when building data analysis pipelines, creating visualizations (Matplotlib/Seaborn), or writing production Python scripts.
Database Schema
Summary
You have successfully:- Connected and managed databases using Database Client in Visual Studio Code as the primary universal method.
- Explored Option 2 using the lightweight SQLite plugin by Alex Covizzi.
- Created the
employee.dbdatabase and managed.sqlscripts. - Created the
departmentsandemployeestables using DDL scripts. - Populated 5 departments and 25 employee records using DML scripts.
- Verified data visually via the interactive data grid and through verification queries.
- Executed sample SQL queries and explored ER Diagram visualization.