SQLite and SQLTools
Installation
Course Workspace
Chinook Database
Connect with SQLTools
First SQL Queries
SQL (Structured Query Language) is a language used to work with relational databases.
With SQL, we can:
SQLite is a lightweight relational database management system. Unlike many database systems, SQLite does not require a separate database server. A complete database can be stored in a single file, such as:
This makes SQLite useful for:
Positron is a data science IDE built on Code OSS. We can use it as an editor for SQL files and extend it with database tools.
.sql scriptsVisual Studio Code is a general-purpose code editor that supports database workflows through extensions.
VSCodium is an open-source build of VS Code with Microsoft telemetry disabled.
In Positron, VS Code or VS Codium, open the Extensions panel.
Search for and install:
mtxr.sqltools)mtxr.sqltools-driver-sqlite)SQLTools provides the database connection interface. The SQLite driver allows SQLTools to connect specifically to SQLite database files.
Installation
Course Workspace
Chinook Database
Connect with SQLTools
First SQL Queries
A workspace is a project folder containing the files needed for a data-management project.
A good workflow is:
data folder for database files.sql folder for saved SQL scripts..sql files.A simple course folder might look like:
Installation
Course Workspace
Chinook Database
Connect with SQLTools
First SQL Queries
For examples in this course, we will use the Chinook sample database.
Chinook represents a digital media store and contains related tables for:
Download the SQLite version of the Chinook database from the project releases:
The SQLite database file is named similar to:
For this course, you may rename it:
Place it in your project’s data folder.
From your course project folder, run:
If the database opens successfully, you should see a SQLite prompt similar to:
SQLite includes special dot commands for working with the database shell.
Try:
This displays the tables in the database.
To inspect the structure of the Customer table:
To exit SQLite:
Warning
SQLite dot commands such as .tables and .schema are commands for the SQLite shell. They are not SQL statements and should not be included inside SQLTools query scripts.
Installation
Course Workspace
Chinook Database
Connect with SQLTools
First SQL Queries
In VS Code or Positron:
data folder.Chinook.You can now use SQLTools to browse tables and run SQL statements.
Inside the sql folder, create a file named:
Use this file to save your SQL statements.
A SQL statement usually ends with a semicolon:
Installation
Course Workspace
Chinook Database
Connect with SQLTools
First SQL Queries
The SELECT statement retrieves data from a database table.
* means to return all columns.
Usually, we only select the columns needed for an analysis.
This makes the query output easier to read and reduces unnecessary data retrieval.
Use LIMIT when you only want to inspect a small number of rows.