Introduction to SQL
SQL has been the language of databases for over 50 years. Before writing your first query, understand what SQL is, how it communicates with a database, and the three categories of commands every SQL developer uses.
What is SQL?
SQL — Structured Query Language — is the standard language for communicating with relational databases. Pronounced either "S-Q-L" or "sequel", it was developed at IBM in the early 1970s based on E.F. Codd's relational model and has been the dominant database language ever since.
SQL is declarative — you describe what data you want, not how to find it. You write SELECT name FROM students WHERE age > 18 and the database figures out the most efficient way to retrieve those records. This is fundamentally different from procedural programming languages where you describe each step.
SQL is defined by the ISO/ANSI standard. MySQL, PostgreSQL, SQLite, and SQL Server all speak SQL — with minor differences in syntax. Core SQL (SELECT, INSERT, UPDATE, DELETE, JOIN) works identically across all of them. That is what this module focuses on.
How SQL Interacts with a Database
SQL does not run directly on data files. It is processed by the Database Management System (DBMS) — software like MySQL or PostgreSQL that sits between your SQL commands and the stored data.
You write SQL
↓
SQL sent to DBMS (MySQL, PostgreSQL, SQLite...)
↓
DBMS parses & validates (is the syntax correct? does the table exist?)
↓
Query optimiser (finds the fastest execution plan)
↓
Execution engine (reads pages from disk, applies indexes)
↓
Result set returned to you
You never touch the raw data files. The DBMS handles storage, retrieval, concurrency, and safety — SQL is simply your instruction to it.
The Three Types of SQL Commands
SQL commands are grouped into three categories based on what they do. Understanding this distinction is important because the categories have different permissions, different effects, and are used at different stages of building a system.
CREATE, ALTER, DROP, TRUNCATE.INSERT, UPDATE, DELETE.SELECT.-- DDL: Define structure
CREATE TABLE students (id INT, name VARCHAR(100));
ALTER TABLE students ADD COLUMN age INT;
DROP TABLE students;
-- DML: Manipulate data
INSERT INTO students (id, name) VALUES (1, 'Uchizi');
UPDATE students SET age = 21 WHERE id = 1;
DELETE FROM students WHERE id = 1;
-- DQL: Query data (never modifies anything)
SELECT * FROM students;
SELECT name, age FROM students WHERE age > 18;
SQL Syntax Rules
SQL has a small set of syntax rules. Break them and you get an error. Follow them and your queries will be readable and portable across different database systems.
SELECT and select work identically. Convention is to write keywords in UPPERCASE and table/column names in lowercase for readability.;. In some tools it is optional for single statements, but always include it — especially when running multiple statements together.'Panji'. Double quotes are used for identifiers (table/column names with spaces): "student name". Never use single quotes for column names.-- this is a comment. Multi-line: /* this spans multiple lines */. Use comments to explain complex queries.