Lesson 1 of 8 · Structured Query Language (SQL)

The SQL Language

What SQL is, the four groups of SQL commands, how to read and write a statement, where you run SQL, and the sample tables used throughout this module.

Beginner 9 sections 6 min read

What's SQL

SQL (Structured Query Language) is the standard language for working with relational databases. You use it to create tables, add and change data, ask questions of the data, and control who can do what.

SQL is declarative: you describe the result you want, and the database works out how to get it. Oracle, SQL Server, PostgreSQL, and MySQL all speak SQL, and the examples in this module run on Oracle.

The four groups of SQL commands

SQL commands fall into four groups:

DDL DML DCL TCL Data Definition Data Manipulation Data Control Transaction Control CREATEALTERDROP SELECTINSERTUPDATEDELETE GRANTREVOKE COMMITROLLBACKSAVEPOINT
DDL (Data Definition Language)
Creates, changes, and removes the structure: tables, indexes, views, and users. Also includes TRUNCATE, which quickly empties a table.
DML (Data Manipulation Language)
Reads and changes the data inside tables. Some references put SELECT in its own group, DQL (Data Query Language).
DCL (Data Control Language)
Gives and takes away permissions.
TCL (Transaction Control Language)
Groups changes into transactions, then saves them for good or undoes them.

The rest of this module takes each group in turn:

The parts of a SQL statement

A SQL statement is one complete command. It's built from clauses, and each clause starts with a keyword:

SELECT FROM WHERE name, city sales.customers city = 'Accra' ; which columns from which table which rows IN PLAIN ENGLISH Show name and city from the customers where city is Accra. SELECT keyword city identifier: a table or column name 'Accra' literal: a fixed value
Keywords
Words with a fixed meaning in SQL, such as SELECT, FROM, and WHERE.
Identifiers
The names of things in the database, such as the table sales.customers and its columns name and city. sales.customers means "the customers table in the sales schema".
Literals
Fixed values you type in: text in single quotes ('Accra'), numbers (250), and dates (DATE '2026-01-10').
Operators
Symbols that compare or combine values, such as =, >, +, and || (join two strings).

Rules for writing SQL

  • End each statement with a semicolon (;) when running it in a tool such as SQL*Plus. It tells the tool the statement is finished.
  • Keywords and names aren't case-sensitive. select, SELECT, and Select all work, and Oracle stores names in uppercase unless you put them in double quotes.
  • Text values are case-sensitive. 'Accra' and 'ACCRA' are different values.
  • Text goes in single quotes. Double quotes are only for names, and you'll rarely need them. To include a single quote in text, double it: 'Kofi''s order'.
  • Spaces and line breaks don't matter. A statement can be on one line or many. Put each clause on its own line so it's easy to read.
  • Comments start with -- and run to the end of the line, or go between /* and */.
-- Hard to read, but valid
select name,city from sales.customers where city='Accra';

-- The same statement, easy to read
SELECT name, city
FROM   sales.customers
WHERE  city = 'Accra';

Where you run SQL

Applications send SQL to the database for you, but DBAs and developers also run it by hand with a client tool:

  • SQL*Plus: Oracle's classic command-line tool, installed with every Oracle database. It's what DBAs reach for on a server.
  • SQLcl: a newer command-line tool from Oracle, with features such as command history and auto-complete.
  • SQL Developer: Oracle's free graphical tool, also available as an extension for Visual Studio Code.

Here's a query run in SQL*Plus. After the results, SQL*Plus tells you how many rows came back:

$ sqlplus kofi@//dbserver:1521/salespdb
SQL> SELECT name, city FROM sales.customers WHERE city = 'Accra';

NAME       CITY
---------- ----------
Kofi       Accra
Yaw        Accra

2 rows selected.

Results in these lessons are trimmed to fit the page; real SQL*Plus output is often wider.

The sample tables

Every lesson in this module uses the same two tables in the sales schema: customers, and the orders they place. Each order belongs to one customer, through its customer_id.

sales.customers customer_idnamecityjoined_on PK NUMBERVARCHAR2(50)VARCHAR2(50)DATE sales.orders order_idcustomer_idorder_dateamountstatus PK FK NUMBERNUMBERDATENUMBER(10,2)VARCHAR2(10) one customer, many orders
PK: primary key, a unique ID for each row. FK: foreign key, which points to a row in another table.

sales.customers

customer_idnamecityjoined_on
1KofiAccra2025-01-15
2AmaKumasi2025-03-02
3YawAccra2025-06-20
4Esi(empty)2025-09-11
5KwameTamale2026-01-05

sales.orders

order_idcustomer_idorder_dateamountstatus
10112026-01-10250SHIPPED
10222026-01-1275.5SHIPPED
10312026-02-031200SHIPPED
10432026-02-1440CANCELLED
10522026-03-01310PENDING
10612026-03-0595PENDING

Notice that Esi has no city, and that Esi and Kwame haven't placed any orders yet. Both details matter in later lessons.

The groups in action

A short script that uses all four groups:

-- DDL: create a table
CREATE TABLE sales.regions (
  region_id NUMBER       PRIMARY KEY,
  name      VARCHAR2(50) NOT NULL
);

-- DML: add a row, then read it
INSERT INTO sales.regions (region_id, name) VALUES (1, 'Greater Accra');
SELECT region_id, name FROM sales.regions;

-- DCL: let the reporting user read the table
GRANT SELECT ON sales.regions TO reporting;

-- TCL: save the changes
COMMIT;

Every platform has its own dialect

SQL is an international standard (ANSI/ISO), and the basics, such as SELECT, INSERT, and JOIN, work almost everywhere. But each platform adds its own functions, data types, and syntax. Each also has its own procedural language for writing stored procedures, with variables, loops, and error handling:

OracleSQL ServerPostgreSQLMySQL
Procedural languagePL/SQLT-SQL (Transact-SQL)PL/pgSQLStored programs, based on the SQL/PSM standard
First 10 rowsFETCH FIRST 10 ROWS ONLYSELECT TOP 10 …LIMIT 10LIMIT 10
Current date and timeSYSDATEGETDATE()NOW()NOW()
Join two strings'a' || 'b''a' + 'b''a' || 'b'CONCAT('a', 'b')

T-SQL is the name for SQL Server's whole dialect, while PL/SQL and PL/pgSQL are procedural languages that sit alongside standard SQL. Either way, code written for one platform usually needs changes to run on another.

Key takeaways

  • SQL is the standard language for relational databases: you describe what you want, and the database works out how.
  • Commands fall into four groups: DDL defines structure, DML works with data, DCL controls permissions, and TCL controls transactions.
  • A statement is made of clauses. Keywords and names aren't case-sensitive, but text values are, and text goes in single quotes.
  • Read a query starting from FROM, then WHERE, then SELECT.
  • Each platform has its own dialect and procedural language, such as PL/SQL, T-SQL, and PL/pgSQL.