How does MySQL determine the end of the statement?


MySQL determines the end of a statement when it encounters any one of the followings −

Semicolon(;)

Generally, MySQL determines the end of the statement, single-line or multiple-line, when it encounters the termination semicolon(;). Consider the examples below,

mysql> Select * from employee; (Single line statement)
mysql> Select *
    -> from
    -> employee; (Multiple line statement)

In both cases, MySQL returns the result set after encountering the semicolon, which means the end of the statement.

\G option

\G option means to send the current state to the server to be executed and display the result in a vertical format. When we use \G and omitting semicolon(;) in a statement (single or multiple lines), MySQL determines the end of the statement as and when it encounters \G. Consider the example below −

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 to send the current state to the server to be executed. When we use \g and omitting semicolon(;) in a statement (single or multiple lines), MySQL determines the end of the statement as and when it encounters \g. It gives the output in the same format as we get by using a semicolon (;). Consider the example below −

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)

Updated on: 22-Jun-2020

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements