CodingNic

SQL Basics

SQL Syntax and Statements

SQL Basics 8 min read

SQL Syntax and Statements

Objectives

By the end of this lesson, you should be able to:

  • Describe the general shape of a SQL statement
  • Explain why the semicolon matters
  • Recognize that SQL keywords aren’t case-sensitive

💡 Why this matters: Every single example for the rest of this course is a SQL statement. Knowing the general shape they all share makes each new one easier to read, even before you know what every word does yet.

⚠️ A note on verification: every statement and result in this lesson was run against a real, live PostgreSQL 18 database.

A Statement Is an Instruction

A SQL statement is one complete instruction to the database, create something, change something, or ask a question. Every statement covered in this course, from a simple SELECT to a multi-table JOIN, is built from the same basic pieces: keywords (the SQL vocabulary itself), the names of things (tables, columns), and values.

sql
SELECT product_name, price FROM products;

SELECT and FROM are keywords, part of SQL’s own vocabulary. product_name, price, and products are names, referring to specific columns and a specific table. Reading left to right, this says: get the product_name and price columns, from the products table.

The Semicolon Ends a Statement

A semicolon (;) marks the end of a statement. Most tools (including everything used to verify this course) will still run a single statement without one, but when more than one statement is sent together, the semicolon is what separates them:

sql
SELECT product_name FROM products;
SELECT category FROM products;

Without the semicolon between them, a database can’t reliably tell where the first statement ends and the second begins. Get in the habit of always including it.

Keywords Aren’t Case-Sensitive

SQL keywords work identically in any case:

sql
select product_name from products where product_name = 'Notebook';

This runs exactly the same as writing SELECT, FROM, and WHERE in capitals. Both are valid, but this course, and most real-world SQL, writes keywords in UPPERCASE. It’s not required, it’s a widely followed convention that makes a keyword instantly visually distinct from a table or column name in the middle of a long query.

Try It

  1. In your own words, explain what a SQL statement is.
  2. Rewrite select product_name from products; using the uppercase convention this course follows.
  3. Explain what would likely go wrong if two statements were sent together with no semicolon separating them.

Recap

  • A SQL statement is one complete instruction, built from keywords, names, and values.
  • A semicolon marks the end of a statement, essential when more than one is sent together.
  • SQL keywords aren’t case-sensitive, but writing them in UPPERCASE is the convention this course follows.

Next lesson: keywords and identifiers, and the difference between SQL’s own vocabulary and the names you choose yourself.