English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The syntax of SQL is constrained by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).
SQL statements are very simple and clear, like ordinary English, but have specific syntax.
SQL statements consist of a series of keywords, identifiers, etc., terminated by a semicolon (;). This is an example of a valid SQL statement.
SELECT emp_name, hire_date, salary FROM employees WHERE salary > 5000;
To improve readability, you can also write the same statement as follows:
SELECT emp_name, hire_date, salary FROM employees WHERE salary > 5000;
Use a semicolon at the end of the SQL statement-It terminates the statement or submits the statement to the database server. However, some database management systems do not have such requirements, but using it is a best practice.
In the following chapters, we will discuss each part of these statements in detail.
Note: SQL statements can contain any number of line breaks, as long as no line break breaks keywords, values, expressions, etc.
Consider another fromEmployeeSQL statements for retrieving records from a table:
SELECT emp_name, hire_date, salary FROM employees;
You can also write the same statement as follows:
select emp_name, hire_date, salary from employees;
SQL keywords are case-insensitive, meaning SELECT is the same as select. However, the case sensitivity of database names and table names may depend on the operating system. Typically, Unix or Linux platforms are case-sensitive, while Windows platforms are not.
Tip:It is recommended to write SQL keywords in uppercase to distinguish them from other text in SQL statements, which helps better understand them.
Comments are just text ignored by the database engine. Comments can be used to provide quick tips about SQL statements.
SQL supports single-line and multi-line comments. To write a single-line comment, use two consecutive hyphens(--)as the starting line. For example:
--Select all employees SELECT * FROM employees;
However, to write multi-line comments, add a slash and an asterisk at the beginning of the comment(/*),then add an asterisk after the comment, and then add a slash(*/),as shown below:
/* Select all salaries greater than5Employees with 000 */ SELECT * FROM employees WHERE salary > 5000;