MySQL determines the end of a statement when it encounters any of the following situations −
Semicolon (;)
Normally, MySQL determines the end of a statement, whether it is a single-line or multi-line statement, when it encounters a terminating semicolon (;). Please refer to the following example:
mysql> Select * from employee; (Single line statement) mysql> Select * -> from -> employee; (Multiple line statement)
In both cases, MySQL returns the result set after encountering a semicolon, which means the statement ends.
\G option
\G option means to send the current status to the server for execution and display the result in vertical format. When we use \G in a statement (single or multiple lines) and omit the semicolon (;), MySQL determines the end of the statement when \G is encountered. Consider the following example -
mysql> Select * from Student\G *************************** 1. row *************************** Name: Gaurav RollNo: 100 Grade: B.tech *************************** 2. row *************************** Name: Aarav RollNo: 150 Grade: M.SC *************************** 3. row *************************** Name: Aryan RollNo: 165 Grade: M.tech 3 rows in set (0.00 sec)
\g option
\g option means sending the current state to the server for execution. When we use \g in a statement (single or multiple lines) and omit the semicolon (;), MySQL determines the end of the statement when it encounters \g. It gives the same output format as what we get using semicolon (;). Consider the following example -
mysql> Select * from Student\g +--------+--------+--------+ | Name | RollNo | Grade | +--------+--------+--------+ | Gaurav | 100 | B.tech | | Aarav | 150 | M.SC | | Aryan | 165 | M.tech | +--------+--------+--------+ 3 rows in set (0.00 sec)
The above is the detailed content of How does MySQL determine the end of a statement?. For more information, please follow other related articles on the PHP Chinese website!