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.
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 (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
SELECTin 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:
| Group | Lesson |
|---|---|
| DML: reading data | Querying Data with SELECT and Summarizing and Joining Data |
| DML: changing data | Changing Data with DML |
| DDL | Defining Structure with DDL and Constraints and Indexes |
| DCL | Controlling Access with DCL |
| TCL | Managing Transactions with TCL |
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:
- Keywords
- Words with a fixed meaning in SQL, such as
SELECT,FROM, andWHERE. - Identifiers
- The names of things in the database, such as the table
sales.customersand its columnsnameandcity.sales.customersmeans "thecustomerstable in thesalesschema". - 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, andSelectall 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_id | name | city | joined_on |
|---|---|---|---|
| 1 | Kofi | Accra | 2025-01-15 |
| 2 | Ama | Kumasi | 2025-03-02 |
| 3 | Yaw | Accra | 2025-06-20 |
| 4 | Esi | (empty) | 2025-09-11 |
| 5 | Kwame | Tamale | 2026-01-05 |
sales.orders
| order_id | customer_id | order_date | amount | status |
|---|---|---|---|---|
| 101 | 1 | 2026-01-10 | 250 | SHIPPED |
| 102 | 2 | 2026-01-12 | 75.5 | SHIPPED |
| 103 | 1 | 2026-02-03 | 1200 | SHIPPED |
| 104 | 3 | 2026-02-14 | 40 | CANCELLED |
| 105 | 2 | 2026-03-01 | 310 | PENDING |
| 106 | 1 | 2026-03-05 | 95 | PENDING |
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:
| Oracle | SQL Server | PostgreSQL | MySQL | |
|---|---|---|---|---|
| Procedural language | PL/SQL | T-SQL (Transact-SQL) | PL/pgSQL | Stored programs, based on the SQL/PSM standard |
| First 10 rows | FETCH FIRST 10 ROWS ONLY | SELECT TOP 10 … | LIMIT 10 | LIMIT 10 |
| Current date and time | SYSDATE | GETDATE() | 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, thenWHERE, thenSELECT. - Each platform has its own dialect and procedural language, such as PL/SQL, T-SQL, and PL/pgSQL.