beginner

Introduction to SQL

5 min read

SQL (Structured Query Language) is the universal standard language used to interact with Relational Database Management Systems (RDBMS). It enables data engineers, software developers, and analysts to store, query, update, and manage structured data efficiently.


1. What is a Relational Database?

A relational database organizes data into structured tables consisting of rows (records) and columns (attributes). Tables can be linked—or related—to each other using common keys.

Key Terminology:

  • Table / Relation: A collection of related data entries structured in rows and columns.
  • Row / Record: A single individual entity entry (e.g., one user).
  • Column / Attribute: A specific property of the data (e.g., email, created_at).
  • Primary Key: A unique column identifier for every row in a table.
  • Foreign Key: A column referencing a primary key in another table to establish relationships.

2. Categories of SQL Commands

SQL commands are divided into five main sub-languages:

  1. DQL (Data Query Language): Retrieve data.
    • SELECT
  2. DDL (Data Definition Language): Define and modify database schemas.
    • CREATE, ALTER, DROP, TRUNCATE
  3. DML (Data Manipulation Language): Modify data records.
    • INSERT, UPDATE, DELETE
  4. DCL (Data Control Language): Manage access permissions.
    • GRANT, REVOKE
  5. TCL (Transaction Control Language): Manage database transactions.
    • COMMIT, ROLLBACK, SAVEPOINT

3. SQL Query Processing Lifecycle

When you execute a SQL query, the database engine processes it through four main phases:

[ SQL Query Text ] ➔ 1. Parser ➔ 2. Optimizer ➔ 3. Execution Engine ➔ [ Result Set ]
  1. Parsing: Checks SQL syntax and verifies table/column permissions.
  2. Optimization: Calculates cost-based plans (choosing indexes, join orders, scan algorithms).
  3. Execution: Reads storage blocks and runs query execution operations.
  4. Result Set: Formats and returns output rows to the client application.