1 SQL Syntax
TopSQL has a clean, English-like syntax. Every SQL statement tells the database what to do — and the database figures out how to do it. Let's build a mini-project from scratch to see how the syntax works in practice.
Step 1: Create a Database
CREATE DATABASE bookstore;Step 2: Create a Table
CREATE TABLE books (
id INT PRIMARY KEY,
title VARCHAR(200),
author VARCHAR(100),
price DECIMAL(8,2),
published DATE
);Step 3: Insert Data
INSERT INTO books (id, title, author, price, published) VALUES
(1, 'SQL in 10 Minutes', 'Ben Forta', 24.99, '2021-11-01'),
(2, 'Learning SQL', 'Alan Beaulieu', 39.99, '2020-04-15'),
(3, 'SQL Pocket Guide', 'Alice Zhao', 19.99, '2021-08-10');Step 4: Query the Data
SELECT title, author, price
FROM books
WHERE price < 30
ORDER BY price;title | author | price -------------------|-------------|------ SQL Pocket Guide | Alice Zhao | 19.99 SQL in 10 Minutes | Ben Forta | 24.99
Syntax Rules to Remember
| Rule | Example | Notes |
|---|---|---|
Statements end with ; | SELECT * FROM books; | Tells the DBMS the statement is complete |
| Keywords are case-insensitive | SELECT = select = Select | Convention: UPPERCASE for keywords |
| Strings use single quotes | WHERE name = 'Alice' | Double quotes are for identifiers in some DBs |
| Single-line comments | -- This is a comment | Everything after -- is ignored |
| Multi-line comments | /* ... */ | For longer explanations |
| Whitespace doesn't matter | You can split queries across lines | Use line breaks for readability |
Best practice: Write SQL keywords in UPPERCASE and table/column names in lowercase. This makes queries much easier to read: SELECT name FROM customers WHERE country = 'UAE'
Key Takeaways
- Every SQL statement ends with a semicolon (
;) - SQL keywords are case-insensitive, but use UPPERCASE by convention
- Strings go in single quotes; comments use
--or/* */ - The basic flow:
CREATEa table,INSERTdata,SELECTto query