Tiyaze Resource Hub — v1.0
Lesson 01 ~25 min read

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 a standard

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.

flow
You write SQLSQL 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.

DDL
Data Definition Language. Defines and modifies the structure of the database — creating tables, altering columns, dropping databases. These commands change the schema. Examples: CREATE, ALTER, DROP, TRUNCATE.
DML
Data Manipulation Language. Works with the data inside the structure — inserting, updating, and deleting records. These commands change the content. Examples: INSERT, UPDATE, DELETE.
DQL
Data Query Language. Retrieves data without changing anything. The entire SELECT family. Some group DQL inside DML, but the distinction is useful — SELECT never modifies data. Examples: SELECT.
sql — command types in practice
-- 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.

Case insensitive
SQL keywords are not case-sensitive — SELECT and select work identically. Convention is to write keywords in UPPERCASE and table/column names in lowercase for readability.
Semicolons
Each SQL statement ends with a semicolon ;. In some tools it is optional for single statements, but always include it — especially when running multiple statements together.
String quotes
String (text) values are wrapped in single quotes: 'Panji'. Double quotes are used for identifiers (table/column names with spaces): "student name". Never use single quotes for column names.
Comments
Single line: -- this is a comment. Multi-line: /* this spans multiple lines */. Use comments to explain complex queries.
Whitespace
SQL ignores extra spaces and line breaks. Write queries across multiple lines to improve readability — the database sees it all as one statement.
// Knowledge Check
A developer runs ALTER TABLE students ADD COLUMN email VARCHAR(150). Which category of SQL command is this?