SQL Syntax
SQL syntax is governed by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).
SQL statements are simple to understand as they use plain English, following a specific syntax.
A SQL statement is composed of a sequence of keywords, identifiers, operators, etc., and terminates with a semicolon.
Some of the key guidelines to write clean and consistent SQL queries.
- SQL keywords are case insensitive.
- Recommended to write the SQL keywords in uppercase to differentiate them from other text in a SQL query.
- Always terminate a SQL query with a semicolon.
- An SQL statement can contain any number of line breaks, without breaking the keywords, values, expressions, etc., before it terminates.
- Database and table names are case-sensitive on Unix and Linux platforms, and case-insensitive in Windows.
SQL Keywords are case-insensitive
The keywords used in the first query are in uppercase and lowercase in the second query.
However, they work the same way as the SQL keywords are case-insensitive.
SELECT * FROM employees WHERE salary > 20000;
select * from employees where salary > 20000;
SQL Statement with line breaks
SQL Query can have any number of line breaks without breaking the query functionality as shown below.
SELECT *
FROM employees
WHERE salary > 20000;
SQL Statement must terminate with a semicolon
All the SQL statements must terminate with a semicolon as shown below.
SELECT * FROM employees WHERE salary > 20000;
Overall
We now know the basic syntax of a SQL query along with some important guidelines.