This article mainly introduces how to use SQL statement rules in MySQL command lines. For more information, see
Rule 1: the SQL statement must end with a semicolon (;) or (\ G ).
A semicolon (;) indicates the end of an SQL statement. If you forget the semicolon and press the Enter key, the following message is displayed on the MySQL client:
mySQL> SELECT * FROM customer->
Because the SQL statement does not end with a semicolon, the client determines that the SQL statement has not ended. [->] is displayed, waiting for the user to continue entering the command until it ends with a semicolon. In some databases, the last semicolon can be omitted.
Rule 2: reserved keywords are case insensitive
Reserved Keywords are keywords defined in SQL. for example, the SELECT and FROM keywords in the preceding query statements are reserved keywords. In SQL, these reserved keywords are case-insensitive. That is to say, all the following statements are correct.
Executed.
mySQL> SELECT * FROM customer;mySQL> select * FROM customer;mySQL> SeLecT * FROM customer;
However, when writing SQL statements, you should keep the keyword size as much as possible. For example, to write reserved keywords in the form of uppercase letters and to write tables or column names in the form of lowercase letters, the SQL statement will also look clear at a glance. In addition, some databases are case sensitive to tables or column names.
Rule 3: free to add blank or line breaks
In the middle of an SQL statement, you can freely add spaces or line breaks. for example, the following languages can be correctly executed.
mySQL> SELECT *-> FROM customer;mySQL> SELECT->*->FROM->customer;
However, adding spaces or line breaks in the middle of a keyword is invalid.
An SQL statement can be written as one line. However, you can add the appropriate line feed to the long periods to facilitate reading.
Line Feed in command statements is a reference standard. for example, the names of Retrieved object columns are listed one by one in the SELECT statement, and the names of Retrieved object tables are listed after the FROM command in the next line, in this way, the entire SQL statement looks distinct.
In addition, you can wrap a line after a column name or table name. for example, you can add an indent (tab) to the column name of the retrieved object after a single row of SELECT columns, list all column names separately in one row.
Rule 4: Use [--] or [/*... */] to add comments.
You can add comments to SQL statements. Annotations are information that is not interpreted by DBMS. Annotations are divided into single-line annotations and multi-line annotations. A single line comment starts with two [-] until the end of a row is treated as a comment. Multi-line comments are strings contained in [/*] and ..
mySQL> SELECT * FROM customer; --THIS IS COMMENTSmysql>/*this/*>is/*>comments*/