Installing SQLite3
On Ubuntu
- Update your package list:sh
sudo apt update - Install SQLite3:sh
sudo apt install sqlite3 - Verify the installation:sh
sqlite3 --version
On Windows
- Download the SQLite tools from the SQLite Download Page.
- Extract the downloaded ZIP file to a directory of your choice.
- Add the directory to your system PATH:
- Open the Start Menu, search for "Environment Variables", and select "Edit the system environment variables".
- Click on "Environment Variables".
- Under "System variables", find the
Pathvariable, select it, and click "Edit". - Click "New" and add the path to the directory where you extracted SQLite tools.
- Verify the installation:sh
sqlite3 --version
Creating a Database using Visual Studio Code
- Open Visual Studio Code.
- Install the SQLite extension by searching for "SQLite" in the Extensions view (
Ctrl+Shift+X). - Create a new file with a
.dbextension, e.g.,mydatabase.db. - Open the Command Palette (
Ctrl+Shift+P) and selectSQLite: Open Database. - Select your newly created database file.
Running Scripts
- Create a new SQL file, e.g.,
script.sql. - Write your SQL commands in the file. For example:sql
CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE ); INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'); - Open the Command Palette (
Ctrl+Shift+P) and selectSQLite: Run Query. - Select your SQL file to execute the commands.
Adding Data
- Open your database in Visual Studio Code.
- Create a new SQL file or use the existing one.
- Write an
INSERTstatement:sqlINSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com'); - Run the query as described in the "Running Scripts" section.
Removing Data
- Open your database in Visual Studio Code.
- Create a new SQL file or use the existing one.
- Write a
DELETEstatement:sqlDELETE FROM users WHERE name = 'Alice'; - Run the query as described in the "Running Scripts" section.
Backup
- Open your terminal or command prompt.
- Use the
.backupcommand to create a backup of your database:shsqlite3 mydatabase.db ".backup mydatabase_backup.db"
This will create a backup file named mydatabase_backup.db in the same directory.