DevLearningTools

LEARN · SQL

SQL Syntax

Learn the building blocks of a SQL statement: keywords, statement structure, semicolons, and the conventions this course follows for readable queries.

Every SQL statement follows the same basic shape: a keyword saying what to do, followed by the details of what to do it to. This lesson covers that shape in general, before the next lessons dig into SELECT specifically.

Learning Objectives

  • Identify the parts of a basic SQL statement.
  • Explain when a semicolon is required versus just good habit.
  • Follow this course's conventions for keyword casing and formatting.

Keyword

SELECT, INSERT, UPDATE...

Details

Columns, table, conditions

Semicolon

Marks the statement's end

The Shape of a Statement

SELECT is a keyword, a reserved word SQL understands as an instruction. first_name, last_name are the columns being asked for. FROM employees names the table. WHERE department = 'Engineering' narrows down which rows. Every SQL statement follows this same pattern: keyword, then the specifics.

MySQL / PostgreSQL / SQLite / SQL Server
SELECT first_name, last_name
FROM employees
WHERE department = 'Engineering';

Keyword Casing

SQL keywords aren't case-sensitive, select first_name from employees runs exactly the same as SELECT first_name FROM employees. This course writes keywords in uppercase and table/column names in lowercase, a widely used convention that makes a query's structure easy to scan at a glance, not a rule the database enforces.

Semicolons

A semicolon marks the end of a statement. Most database tools accept a single statement without one, but it's required when running multiple statements together, like the two SELECTs above, so the database knows where one ends and the next begins. It's good habit to always include it.

MySQL / PostgreSQL / SQLite / SQL Server
SELECT * FROM employees;
SELECT * FROM departments;

Try It Yourself

Spot the two mistakes in this statement, then write a corrected version: select * from Employees where Salary > 90000

Answer
-- Mistake 1: missing semicolon at the end.
-- Mistake 2 (arguably a style issue, not an error): mixed casing
-- makes it harder to scan, this course's convention keeps keywords
-- uppercase and identifiers lowercase.
SELECT * FROM employees WHERE salary > 90000;

Frequently Asked Questions

Are table and column names case-sensitive?

It depends on the database and how the table was created. PostgreSQL treats unquoted names as lowercase by default, MySQL's behavior can depend on the operating system it's running on. The safest habit is picking a casing convention for your own names and staying consistent with it.

Does whitespace or line breaks matter in SQL?

No, SQL ignores extra spaces, tabs, and line breaks between keywords. Splitting a query across multiple lines (like the SELECT example above) is purely for readability.

What are reserved words, and can I use them as a column name?

Reserved words are keywords SQL uses for its own syntax, like SELECT, ORDER, or GROUP. Using one as a column name usually requires quoting it specially (differently per database), which is why it's best avoided entirely when naming your own columns.

Common Beginner Mistakes

Forgetting the semicolon when running multiple statements together

Without it, the database can't tell where one statement ends and the next begins, and the whole batch can fail with a confusing syntax error.

Using a reserved word as a column or table name

Naming a column order or group creates constant friction, since SQL will try to interpret it as the keyword instead. Pick a different name rather than fighting with quoting rules later.

Best Practices

  • Write keywords in UPPERCASE and your own table/column names in lowercase, for readability, even though SQL itself doesn't require it.
  • Always end a statement with a semicolon, even when the tool you're using doesn't strictly require it for a single query.
  • Avoid naming a column or table after a SQL reserved word.

Interview Questions

Is SELECT First_Name FROM Employees valid, and does it behave the same as SELECT first_name FROM employees?

The keyword SELECT works identically regardless of case. Whether First_Name and first_name refer to the same column depends on the specific database and how the table was created, some are case-sensitive for identifiers, some aren't, which is why consistent casing habits matter.

Why is a semicolon required when running two statements in one script, but not for a single query in most tools?

The semicolon tells the database parser where one statement ends and the next begins. With only one statement, most tools can safely assume it ends at the end of input, but with two or more, omitting the semicolon leaves the boundary ambiguous.

Summary

This lesson covered the basic shape of a SQL statement, this course's keyword-casing convention, and when a semicolon is required versus just good habit.

What's Next?

The next lesson covers SELECT in depth, the statement you'll use most often in this entire course.

</>

Ready to Practice SQL?

Write and run real SQL queries online, right in your browser, no install or signup required. Pick a playground based on which database you want to practice on.

SQLite / PostgreSQL

Fast, no server, no ads.

Open DB Fiddle ↗

MySQL / SQL Server

Switch databases with one dropdown.

Open SQL Fiddle ↗

Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.