Back to Blog

SQLite for Beginners: CREATE TABLE, INSERT & SELECT in Neovim | Episode 1

Celest KimCelest Kim

Video: SQLite for Beginners: CREATE TABLE, INSERT & SELECT in Neovim | Episode 1 by Taught by Celeste AI - AI Coding Coach

Watch full page →

SQLite for Beginners: CREATE TABLE, INSERT & SELECT in Neovim

Learn how to create and manipulate a simple SQLite database directly within Neovim. This tutorial covers creating a contacts table, inserting data, and querying it using basic SQL commands, all while running SQLite commands from the command line inside your editor.

Code

-- Set output mode to column for readable tables and turn headers on
.mode column
.headers on

-- Create a table named contacts with three columns: id, name, and email
CREATE TABLE contacts (
  id INTEGER PRIMARY KEY,   -- unique ID auto-incremented
  name TEXT,               -- contact's name
  email TEXT               -- contact's email address
);

-- Insert three rows into the contacts table
INSERT INTO contacts (name, email) VALUES ('Alice Johnson', 'alice@example.com');
INSERT INTO contacts (name, email) VALUES ('Bob Smith', 'bob@example.com');
INSERT INTO contacts (name, email) VALUES ('Carol Lee', 'carol@example.com');

-- Query all rows and columns from contacts
SELECT * FROM contacts;

Key Points

  • Use CREATE TABLE to define a table’s structure with column names and data types.
  • Insert data rows using INSERT INTO, enclosing text values in single quotes.
  • SELECT * FROM retrieves all data from a table and is the most common query.
  • SQLite commands like .mode column and .headers on improve query output readability.
  • You can run SQL files directly from Neovim using :!sqlite3 filename.sql to see results immediately.