The rule 1:sql statement must end with a semicolon (;) or (\g)
The semicolon (;) is the end flag for the SQL statement. If you forget the semicolon and press ENTER directly, the following will appear on the MySQL client
- Mysql> SELECT * FROM Customer
- -
Because the client does not end up with a semicolon, it shows that the SQL statement does not end, and the [->] waits for the user to continue entering the command until the semicolon ends. In some databases, the case of omitting the last semicolon is supported.
Rule 2: Reserved keywords are case insensitive
Reserved keywords are pre-defined keywords in SQL, such as SELECT, from, and so on in the search statement above, which belong to the reserved keyword. These reserved keywords are case insensitive in SQL. In other words, the following statements are correct to
Be executed.
- Mysql> SELECT * from customer;
- Mysql> select * from Customer;
- Mysql> SeLecT * from customer;
However, in general, when you write SQL, you want to keep the size of the keyword as uniform as possible. For example, if you write a reserved keyword in uppercase letters, write a table or column name in lowercase letters, the SQL statement will also look a glance. In addition, depending on the database used, some databases are case-sensitive for table or column names.
Rule 3: Free to add blanks or line breaks
In the middle of the SQL statement, you are free to add spaces or line breaks, such as the following languages can be executed correctly.
- Mysql> SELECT *
- from customer;
- Mysql> SELECT
- ->*
- ->from
- ->customer;
However, it is not legal to add a space or a newline character to the middle of a keyword.
An SQL statement can be written as a single line, but for those long words, you can add the appropriate newline character to it so that it is easy to read.
Wrapping in a command statement is a standard that can be referenced, for example, to list the retrieved object column names in a SELECT statement, and the next line's from command to list the retrieved object table names so that the entire SQL statement looks hierarchical.
In addition, the column name or table name can be wrapped, for example, a single row of the Select column, followed by the retrieved object column name before adding an indentation (tab), all the column name one by one rows are listed separately.
Rule 4: Add comments using [--] or [/* ... */]
Comments can be added to the SQL statement. Comments are information that is not interpreted by the DBMS. Comments are also divided into single-line comments and multiline comments. A single-line comment begins with two [-] until the end of a line is considered a comment. A multiline comment consists of a string consisting of [/*] and [/*].
- Mysql> SELECT * from customer; --this is COMMENTS
- Mysql>/*this
- /*>is
- /*>comments*/
The original link in the MySQL command line using the rules of SQL statements, reproduced please specify the source: http://uphtm.com/database/149.html
Rules for using SQL statements on the MySQL command line