-1

In MySQL query, what does the $$ signify?

DELIMITER $$
CREATE TRIGGER before_population_update
BEFORE UPDATE ON City
FOR EACH ROW BEGIN
INSERT INTO City_Changes
SET ACTION = ‘update’,
CityID = OLD.ID,
Population = OLD.Population,
User = USER(),
ChangedOn = NOW();
END $$
DELIMITER ;
Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
gymcode
  • 4,431
  • 15
  • 72
  • 128
  • mysql default delimiter is ; and your defining some other delimiter in above trigger definition $$ – Mahesh Madushanka Jun 29 '16 at 07:05
  • You are defining it as a delimiter in the first line. What do you think it means? It has no special meaning. – TZHX Jun 29 '16 at 07:06
  • that will help you to paste all the text untill it $$ to execute in single block – Mahesh Madushanka Jun 29 '16 at 07:06
  • 1
    i think this question should exist, but still be marked as a duplicate. if you didn't know that `$$` was a delimiter, you wouldn't know to search for that and instead search for the title of this question. – SovietFrontier Sep 04 '19 at 15:37

1 Answers1

4

Triggers and stored procedures are [potentially] made up of several statements, which are each terminated by ;. Since ; is used to terminate an individual statement, they need a way to indicate the procedure/trigger is done - and this is where the delimiter command comes into play.

On the first row, we define the following trigger will be delimited (ended) by the $$ sequence. We then go on to declare a trigger (starting with create trigger and ending with $$ as we defined). Then, on the last row, we reset the delimiter to the default ; for good measures.

Mureinik
  • 297,002
  • 52
  • 306
  • 350