0
 Delimiter$$
    CREATE TRIGGER after_finisher_update
    AFTER UPDATE ON Booklist1
    FOR EACH ROW 
    BEGIN
        UPDATE Booklist1
        SET Finished = 'yes'
        WHERE Current_Page = Page_Count
    END $$  

I have a table with multiple columns that forms a booklist (title, author... ect). I want my "Finished" Column (which defaults to no) to switch to "yes" once current_page = page_count.

  • Can someone please explain what delimiter means and what delimiter$$ means?
  • When I conclude with END$$ (omitted from code above) my terminal functions improperly. Whatever I type just goes into the console and gets returned word for word but does nothing. Does anyone know this error? I tried to look it up a bit but could find nothing. It happens with other entries too.

Thank you.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • So, is this a problem with the trigger itself or with something else like the console you are using to debug it? – LMC Aug 07 '18 at 19:43
  • 1
    I'll try, but I might be a little off... MySQL tries to execute any string of code that has a delimiter at its end. Normally, the delimiter is ';'. However, when compiling a procedure, say, you don't want MySQL to execute the code until its compilation is complete. So, you change the delimiter to something else. '$$' is a popular choice. – Strawberry Aug 07 '18 at 19:45
  • [Here](https://stackoverflow.com/a/10259528/2834978) is a good answer to a similar question. – LMC Aug 07 '18 at 19:46
  • @LuisMuñoz This is a problem with my trigger. I'm not sure how to write it. The console bug is separate. It comes up when I have a typo/ mistake in my code every once in a while. The only way I've been able to solve it is by closing and re-opening the terminal. – marc toney Aug 08 '18 at 16:08
  • What terminal is that one? – LMC Aug 08 '18 at 17:31

1 Answers1

0

Mysql use ; to mark the end of the statement .

When you define a procedure , function , or a trigger you are going to use multiple statements .

You need to tell mysql where is the end of function/procedure/trigger statement .

if type delimeter // i will use // to indicate the end of a statement .

so this block :

select now() ;
do sleep(1) ;
select now() ;

can be replace by :

delimiter //
select now() //
do sleep(1) //
select now() //
delimiter ;

A example for creating a trigger using $$ as a separator :

delimiter $$
create trigger trg_table_insert  after insert  on table
for each row
begin
        insert into  table_log ( dml_type , col_a,col_b , col_c ) value ( 'I', new.col_a,new.col_b,new.col_c );
end
$$
delimiter ;

AND each time i revert the delimeter to ; .

^^^^^^^ you do this to have the regular behavior of mysql .

Community
  • 1
  • 1
EchoMike444
  • 1,513
  • 1
  • 9
  • 8
  • I think I understand. Basically saying Delimiter $$ tells MySQL that you are about to write a procedure. After finishing the procedure you will write what you specified in the begging. IE ` Delimiter $$ .... .... $$ (this will tell MySQL you are ending the procedure. Still confused why you put delimiter ; at the end though. – marc toney Aug 08 '18 at 16:06