Initial Setup
Learn SQL fundamentals and execute your first queries. This guide introduces SQL syntax and basic operations using SQLite (no installation required).
π― What You’ll Accomplish
By the end of this tutorial, you’ll have:
- β SQLite installed and ready to use
- β Understanding of basic SQL syntax
- β Your first database and table created
- β Basic queries executed
π Prerequisites
- Basic familiarity with your computer’s terminal/command line
- No prior SQL or database experience required
πΎ Step 1: Install SQLite
SQLite comes pre-installed on macOS and most Linux distributions. For Windows, download from sqlite.org.
Verify Installation
sqlite3 --versionExpected output:
3.x.xποΈ Step 2: Create Your First Database
sqlite3 myapp.dbThis creates a new database file and opens the SQLite shell.
π Step 3: Create Your First Table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);View tables:
.tables
.schema usersπ Step 4: Insert and Query Data
Insert data:
INSERT INTO users (name, email) VALUES
('Alice Johnson', 'alice@example.com'),
('Bob Smith', 'bob@example.com'),
('Charlie Brown', 'charlie@example.com');Query data:
SELECT * FROM users;
SELECT name, email FROM users WHERE name LIKE 'A%';
SELECT COUNT(*) FROM users;β Verification Checklist
Before moving forward, verify:
-
sqlite3 --versionshows SQLite installed - You created a database file
- You can create tables and insert data
- You can query data with SELECT
π You’re Done!
You’ve successfully learned basic SQL operations. You’re ready for more advanced queries.
π What’s Next?
Quick learner: SQL Quick Start
Code-first learner: SQL By Example
π Troubleshooting
SQLite Not Found
Problem: “sqlite3: command not found”
Solution: Install SQLite:
# macOS
brew install sqlite
# Ubuntu/Debian
sudo apt install sqlite3
# Windows: Download from sqlite.orgLast updated