Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does DELIMITER // do in a Trigger?

Tags:

sql

mysql

DELIMITER // 

What is the of use of it?

like image 722
Kevin Avatar asked Aug 28 '09 12:08

Kevin


People also ask

What is the purpose of the delimiter?

A delimiter is a sequence of one or more characters for specifying the boundary between separate, independent regions in plain text, mathematical expressions or other data streams.

What is the use of delimiter in SQL?

A delimiter is a simple or compound symbol that has a special meaning to PL/SQL. For example, you use delimiters to represent arithmetic operations such as addition and subtraction.

What is delimiter $$ in SQL?

You define a DELIMITER to tell the mysql client to treat the statements, functions, stored procedures or triggers as an entire statement. Normally in a . sql file you set a different DELIMITER like $$. The DELIMITER command is used to change the standard delimiter of MySQL commands (i.e. ;).

Why do we change delimiter in mysql?

By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.


2 Answers

It changes the statement delimiter from ; to //. This is so you can write ; in your trigger definition without the MySQL client misinterpreting that as meaning you're done with it.

Note that when changing back, it's DELIMITER ;, not DELIMITER; as I've seen people try to do.

like image 107
chaos Avatar answered Oct 02 '22 05:10

chaos


In SQL you close each statement with a delimiter, which is by default a semicolon (;). In a trigger you need to write multiple statements, each ending in a semicolon. To tell MySQL that those semicolons are not the end of your trigger statement, you temporarily change the delimiter from ; to //, so MySQL will know that the trigger statement only ends when it econunters a //.

like image 27
Zed Avatar answered Oct 02 '22 05:10

Zed