Embedded Relational Database
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files.
Created by D. Richard Hipp in 2000, SQLite is the most widely deployed database engine in the world, found in countless applications including every Android and iOS device, most web browsers, and many other applications. SQLite's source code is in the public domain, making it free to use for any purpose.
-- Create a table CREATE TABLE contacts ( contact_id INTEGER PRIMARY KEY, first_name TEXT NOT NULL, last_name TEXT NOT NULL, email TEXT, phone TEXT, created_at TEXT DEFAULT (datetime('now')) ); -- Insert data INSERT INTO contacts (first_name, last_name, email, phone) VALUES ('John', 'Smith', '[email protected]', '555-123-4567'), ('Jane', 'Doe', '[email protected]', '555-987-6543'); -- Query data SELECT * FROM contacts; -- Update data UPDATE contacts SET email = '[email protected]' WHERE contact_id = 1; -- Delete data DELETE FROM contacts WHERE contact_id = 2;
-- SQLite dynamic typing (type affinity) CREATE TABLE dynamic_example ( id INTEGER PRIMARY KEY, flexible_column -- No type specified, can hold any data type ); INSERT INTO dynamic_example (flexible_column) VALUES (42), -- Integer (3.14159), -- Real ('text value'), -- Text (NULL), -- NULL (x'DEADBEEF'); -- BLOB (binary data) -- Using SQLite date/time functions SELECT date('now'), time('now'), datetime('now', 'localtime'), strftime('%Y-%m-%d %H:%M', 'now'); -- Full-text search (requires FTS extension) CREATE VIRTUAL TABLE articles USING fts5( title, body ); INSERT INTO articles VALUES ('SQLite Tutorial', 'SQLite is a lightweight database...'), ('Database Design', 'Proper database design is essential...'); -- Search for content SELECT * FROM articles WHERE articles MATCH 'sqlite';
// JavaScript with Node.js (using the sqlite3 package) const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database('./mydb.sqlite'); // Create table db.run(`CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE )`); // Insert data db.run(`INSERT INTO users (name, email) VALUES (?, ?)`, ['Alice', '[email protected]'], function(err) { if (err) { return console.error(err.message); } console.log(`User added with ID: ${this.lastID}`); } ); // Query data db.all(`SELECT * FROM users`, [], (err, rows) => { if (err) { return console.error(err.message); } rows.forEach(row => { console.log(row); }); }); // Close the database connection db.close();
SQLite is used in a wide variety of applications:
SQLite has evolved significantly since its creation:
SQLite is known for its consistent backward compatibility and reliability. The development team values correctness and long-term stability over adding new features.
Here are some excellent resources for learning SQLite:
Technologies related to SQLite: