Chapter 2: SQL Syntax Basics

SQL Syntax Basics

Alright, class! Welcome to Chapter 2 — the place where we stop talking about SQL and actually start speaking it. Think of this as learning the grammar and pronunciation of a new language. If you get these basics right, everything else in SQL will feel much easier and natural.

Today we’re going to cover four super-important foundational things:

  • The basic structure of SQL statements
  • How to write comments (so you can explain your code to yourself and others)
  • Case sensitivity (does uppercase/lowercase matter?)
  • Semicolon usage (when and why you need that little ; at the end)

I’m going to explain everything like we’re sitting together in a Mumbai café, with me drawing on a napkin and showing you real examples. Let’s go step by step!

1. Basic Structure of SQL Statements

Every SQL statement follows a very predictable pattern. It’s almost like filling in a template. Most statements have these parts:

SQL

Here are the most common types of SQL statements you’ll write:

  • SELECT (to read data) Most common statement in the world!
    SQL
  • INSERT (to add new data)
    SQL
  • UPDATE (to change existing data)
    SQL
  • DELETE (to remove data)
    SQL
  • CREATE (to make new tables, databases, etc.)
    SQL

Golden Rules for Structure:

  • Keywords like SELECT, FROM, WHERE, INSERT, UPDATE, etc. are written in uppercase by convention (though not required).
  • You can write the entire query on one line or spread it over multiple lines — the database doesn’t care.
  • Indentation and line breaks are purely for human readability — highly recommended!

Real-life example (imagine we have a table called students):

SQL

Always write it the “good” way — your future self (and teammates) will thank you!

2. Comments in SQL

Comments are notes in your code that the database completely ignores. They are only for humans — to explain what the query does, why you wrote it a certain way, or to temporarily disable parts of code.

There are two ways to write comments in SQL:

A. Single-line comment → use — (two dashes) Everything after — on that line is ignored.

SQL

B. Multi-line comment → use /* … */ Everything between /* and */ is ignored, even across many lines.

SQL

Pro Tip: Use comments generously! Especially when:

  • The query is complex
  • You’re doing something tricky
  • You’re about to share the query with your team

3. Case Sensitivity

Here’s the golden rule that confuses almost everyone at first:

SQL keywords are NOT case-sensitive.

You can write SELECT, select, SeLeCt, sElEcT — the database treats them all the same.

BUT — the actual data (values inside tables) IS case-sensitive in most databases!

Examples:

SQL

Important differences between popular databases (2026 status):

Database Keywords case-sensitive? Table/Column names case-sensitive? Data (string values) case-sensitive?
MySQL No Depends on OS (Linux = Yes, Windows = No) Yes
PostgreSQL No Yes (by default) Yes
SQL Server No No (unless you use quoted identifiers) Yes (unless collation is case-insensitive)
Oracle No No (unless quoted) Yes
SQLite No Yes (unless PRAGMA case_sensitive_like) Yes

Best Practice (what most professionals do):

  • Write keywords in UPPERCASE (SELECT, FROM, WHERE, etc.)
  • Write table and column names exactly as they were created (usually lowercase or snake_case)
  • Be careful with string comparisons — use functions like LOWER() or UPPER() if you want case-insensitive search:
SQL

4. Semicolon Usage (;)

The semicolon ; is like the full stop (period) at the end of an English sentence.

When do you need it?

Situation Do you need ; ? Example
Most tools & clients (MySQL Workbench, pgAdmin, DBeaver, VS Code) Yes — almost always SELECT * FROM employees;
Inside stored procedures / functions / triggers Yes between statements SET @count = 0; SELECT @count;
Multiple statements in one script Yes between each INSERT …; UPDATE …; DELETE …;
Some web apps / ORMs (like Python’s SQLAlchemy) Sometimes optional Depends on the driver
Oracle SQL*Plus (older tool) Yes (or use / instead)
SQLite command-line tool Optional (but recommended)

Rule of Thumb for 2026: Always put a semicolon at the end of every SQL statement. It’s safe, portable, and prevents 90% of “why isn’t my query running?” errors.

Funny real-life story: A junior developer once spent 3 hours wondering why his query failed… only to realize he forgot the ; in a production script. The database silently waited for more input — classic!

Quick Recap with a Full Example

SQL

See? Clean, commented, properly cased, and ends with ;.

That’s it for SQL Syntax Basics! You now know how to write clean, readable, and correct SQL.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *