Home > Database > Mysql Tutorial > How does MySQL determine the end of a statement?

How does MySQL determine the end of a statement?

王林
Release: 2023-09-04 13:29:02
forward
1119 people have browsed it

How does MySQL determine the end of a statement?

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)
Copy after login

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)
Copy after login

\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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template