# Working with SQLite

SQLite is a lightweight file based database that supports SQL queries. Create a new SQLite database in the container and execute some commands against it.

{% tabs %}
{% tab title="Exercise" %}

* Open the integrated terminal and browse to "/"
* Create a folder called "data"
* Move into that folder and create a new SQLite database with `sqlite3 lamp.db`
* Connect to the database with the SQLite Extension
* Create a new table called "colors"
* Insert a few records
* Select the records back out
  {% endtab %}

{% tab title="Answer" %}

* Open the integrated terminal with (**Cmd/Ctrl + \`**)
* Move to the root directly of the container

```
cd /
```

* Create a folder called "data"

```
mkdir data
```

* Move into that new folder

```
cd data
```

* Create a new SQLite database called "lamp"

```
sqlite3 lamp.db
```

* Display the database that was created with the ".databases" command

```
.databases
```

* Type `.quit` to exit the SQLite prompt

![](/files/-Lm77jyxsqT6tKrrJ2xK)

* Open the Command Prompt (**Cmd/Ctrl + Shift + P**)
* Select "SQLite: Open Database"

![](/files/-Lm77vlDQCA5PvnFAloB)

* Select "Choose database from file" in the prompt

![](/files/-Lm784og5vRPgrFZY5IW)

* Type "/data/lamp.db" in the prompt

![](/files/-Lm78GZ_UtJQ8dbEtPU9)

* Open the Explorer view (**Cmd/Ctrl + Shift + E**)
* Notice there is now a "SQLite Explorer" view
* Right-click the lamp.db database and select "New Query"

![](/files/-Lm78fLyz0qw4Gdx9xRk)

* Use the commands found in "sqlite.sql" in the project to...
  * Create a table
  * Insert a color
  * Select a record

```
-- SQLite
CREATE TABLE colors (
 id INTEGER PRIMARY KEY,
 color TEXT NOT NULL
);

INSERT INTO colors (id, color) VALUES (1, 'Blue')

SELECT * FROM colors
```

* Each block must be run by itself. Highlight the block to run.
* Open the Command Palette and select "SQLite: Run Selected Query"

![](/files/-Lm79aeTCTDCiuUKkBr_)

* View the query results in split pane mode

![](/files/-Lm79jSN1pHvblY3mHyg)
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://burkeholland.gitbook.io/vs-code-can-do-that/exercise-7-working-with-data/working-with-sqlite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
