SQL Syntax
SQL Syntax
SQL syntax refers to the rules that define how SQL statements are written. SQL statements are made up of keywords, table names, column names, operators, and values.
Although SQL is not case-sensitive for keywords, it is common practice to write keywords in uppercase to improve readability.
SQL Statements
Most SQL statements follow a structured pattern. For example, a SELECT query typically includes SELECT, FROM, and optionally WHERE and ORDER BY.
SELECT column1, column2 FROM table_name WHERE condition ORDER BY column1;
Each part of the statement has a specific purpose. SELECT defines what to retrieve, FROM defines where to retrieve it from, and WHERE filters the results.
Database Tables
Data in a relational database is stored in tables. A table consists of rows and columns.
- Column defines the type of data (for example, name or price).
- Row represents one record in the table.
Example table structure:
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
This table stores customers with an id, name, and email address.
Semicolon After SQL Statements?
A semicolon (;) is used to separate SQL statements. In many database systems, it is required when running multiple statements in a script.
In some tools, a single statement may work without a semicolon, but it is best practice to always include it.
SELECT * FROM customers;
Some of The Most Important SQL Commands
- SELECT – retrieve data from a table
- INSERT INTO – insert new records
- UPDATE – modify existing records
- DELETE – remove records
- CREATE TABLE – create a new table
- ALTER TABLE – modify a table structure
- DROP TABLE – delete a table
In the next lessons, we will explore each of these commands step by step with practical examples.