This article is a beginner friendly guide that gets you started into learning SQL as a programming language.
Introduction
Relational databases store data in tabular form, often referred to as structured data. The alternative is Unrelational databases. Now SQL is simply the programming language that enables you to do so. SQL stands for Structured Querry Language
Basics
To understand a Structured Querry Language , these 4 concepts should come in mind:
Tables - data organized into rows and columns, similar to a spreadsheet eg Customer's table
rows - a single record in a table eg a specific name,'Ahmed'
columns - a single attribute or field eg customer_name
Databases - A Database is like a house that stores the organised data electronically making it easier and safer to find, retrieve and modify the data.This is usually done by the help of a software.
To illustrate more , check the image below:
The icons are SQL databases and Dbeaver is the software .
SQL command categories:
- DDL - Data Definition Language Defines and modifies the structure of the database itself: tables, schemas, and constraints.
create- building a new table or a databasealter- changing an existing table's structuredrop- deleting a table or databbase entirelytruncate- deleting the content inside a table but maintainging the structure
A data engineer setting up a new pipeline will lean on DDL to create the tables that will hold incoming data, and adjust them with ALTER as requirements change.
DQL - Data Querry Language
Is used to retrieve data without changing it. Common key word isselect.
A data analyst spends most of their day writing DQL (SELECT) queries — pulling metrics, building reports, and answering ad hoc business questions.TCL - Transaction Control Language
Manages groups of changes as a single unit, ensuring consistency of data
commit- save all changes made in a transactionrollback- undo changes made in a transactionsavepoint- set a point within a transaction to roll back to, without undoing everything
Now a common question will be what is a transaction.
Well a transaction is like a single unit of work made up of one or more operations eg deleting, updating, writting data that either completes or fails.
Think of it as an all or nothing rule. All steps work, changes are saved but if a single step doesnt, all previous changes are undone.
In systems handling money or critical records, TCL ensures that a group of related changes either all happen or none do. For instance, transferring funds between two bank accounts involves debiting one and crediting another — COMMIT only fires once both steps succeed, and a failure triggers a rollback so the data never ends up half-updated.
- DML - Data Manipulation Language Used for working with the data inside a table.
insert- adding new rowsdelete- removing rowsupdate- modifying exisiting rows
An application connected to the database uses DML constantly in the background: every time a user signs up, places an order, or updates their profile, the app runs INSERT, UPDATE, or DELETE statements.
5.DCL - Data Control Language
Basically manages who can do what.
grant- gives a user permission to perform a certain actionrevoke- takes the permission away
A database administrator (DBA) uses DCL to control who has access to sensitive tables — for example, granting an analyst read-only access while restricting DELETE permissions to a small team.
Getting started on queries
The select statement is where all sql work begins.
select first_name, last_name
from customers
where county = 'Mombasa'
order by age desc;
first_name, last_name, county, age are all columns in our table.
The table name is called customers, while 'Mombasa' is a value in the column county.
The example above is a simple sql querry just to get you started as a beginner, once you have mastered these concepts, next thing you will dive into is filtering and operations , and joins.

Top comments (0)