Why do we need to change the delimiter for creating a trigger?

MySQLMySQLi Database

As we know that in MySQL we use the delimiter semicolon (;) to end each statement. The semicolon is the by default delimiter in MySQL. We need to change the delimiter, while creating a trigger, to tell MySQL that this is not the end of our trigger statement because we can use multiple statements in the trigger. We can change the delimiter temporarily by DELIMITER // statement to change the delimiter from Semicolon (;) to two back-slash (//). After this MySQL would know that the triggering statement only ends when it encounters a two back-slash (//). Following is an example of changing the delimiter −

mysql> DELIMITER //

Now to end the MySQL statements, the delimiter would be a two back-slash (//). And to change it again to a semicolon(;), we can use the following statement −

mysql> DELIMITER ;

Remember that there must be a space between the keyword DELIMITER and the symbol which we want to use as a delimiter.

raja
Published on 22-Feb-2018 12:01:23
Advertisements