Skip to content

Installing SQLite3

On Ubuntu

  1. Update your package list:
    sh
    sudo apt update
  2. Install SQLite3:
    sh
    sudo apt install sqlite3
  3. Verify the installation:
    sh
    sqlite3 --version

On Windows

  1. Download the SQLite tools from the SQLite Download Page.
  2. Extract the downloaded ZIP file to a directory of your choice.
  3. 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 Path variable, select it, and click "Edit".
    • Click "New" and add the path to the directory where you extracted SQLite tools.
  4. Verify the installation:
    sh
    sqlite3 --version

Creating a Database using Visual Studio Code

  1. Open Visual Studio Code.
  2. Install the SQLite extension by searching for "SQLite" in the Extensions view (Ctrl+Shift+X).
  3. Create a new file with a .db extension, e.g., mydatabase.db.
  4. Open the Command Palette (Ctrl+Shift+P) and select SQLite: Open Database.
  5. Select your newly created database file.

Running Scripts

  1. Create a new SQL file, e.g., script.sql.
  2. 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');
  3. Open the Command Palette (Ctrl+Shift+P) and select SQLite: Run Query.
  4. Select your SQL file to execute the commands.

Adding Data

  1. Open your database in Visual Studio Code.
  2. Create a new SQL file or use the existing one.
  3. Write an INSERT statement:
    sql
    INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');
  4. Run the query as described in the "Running Scripts" section.

Removing Data

  1. Open your database in Visual Studio Code.
  2. Create a new SQL file or use the existing one.
  3. Write a DELETE statement:
    sql
    DELETE FROM users WHERE name = 'Alice';
  4. Run the query as described in the "Running Scripts" section.

Backup

  1. Open your terminal or command prompt.
  2. Use the .backup command to create a backup of your database:
    sh
    sqlite3 mydatabase.db ".backup mydatabase_backup.db"

This will create a backup file named mydatabase_backup.db in the same directory.