add tag
Anonymous 2191
I have a question about this fiddle:

<>https://dbfiddle.uk?rdbms=mariadb_10.4&fiddle=07678d74a6c72c3581f6420f64f20014

I have the exactly same code on my phpMyaAmin SQL command, but on phpMyAdmin return this in create trigger section.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 8

My phpMyAdmin Server version: 10.4.21-MariaDB - mariadb.org binary distribution,

Could anyone help please?
Top Answer
Andriy M
Not a MariaDB or phpMyAdmin expert but I am *guessing* the issue might have to do with specifying a delimiter for a compound (multi-statement) command.  Your trigger's body consists of multiple statements, and they need to have delimiters between them.  The semi-colon is the standard delimiter.  But phpMyAdmin may also be using the semi-colon as a *batch* delimiter, it looks for semi-colons in your code to split it into pieces in order to feed MariaDB with your code piece by piece, rather than as a single script.  This way your trigger script is mercilessly ripped apart and MariaDB ends up getting the first fragment of it as just

```#  
CREATE TRIGGER Update_trigger
BEFORE INSERT ON product_price
FOR EACH ROW

BEGIN
    IF (NEW.product_id = 'P9999') 
    
    THEN SET NEW.product_id = 'name99', NEW.value_price = 999  
```

which makes no sense, as there is no `END IF` to the `IF`, nor is there an `END` to the `BEGIN`.  Note that the last line is line number 8, which is the line referred to in the error message.

Your phpMyAdmin needs a way to understand that the entire `CREATE TRIGGER` script needs to be sent to MariaDB as a whole, not in multiple separate pieces.  I'm not sure what should be the way in your case, as I hear there are different ways depending on the version.

One way that *might* work is to specify a different delimiter with the `DELIMITER` command.  `DELIMITER` is not a MariaDB instruction, it is a command that is to be interpreted by phpMyAdmin, and usually you are using it in pairs, like this:

```
DELIMITER $$  /* just an example */

...  /* a piece of code that may contain semi-colons */

$$  /* the above-specified delimiter, used here to mark the end of a batch */

DELIMITER ;  /* back to treating the semi-colon as the batch delimiter */
```

In the above example, everything between `DELIMITER $$` and the first occurrence of `$$` further down the code would be sent by phpMyAdmin to the server as a single script.  The second `DELIMITER` command is needed to switch phpMyAdmin back to using the standard command delimiter (`;`) as the batch delimiter as well[^1].

[^1]: You do not really have to issue the second `DELIMITER` command, but you might *want* to, so as to continue sending other (non-compound) commands in that phpMyAdmin session in a regular fashion, delimiting them with a `;` rather than `$$`.

Your `CREATE TRIGGER` command, therefore, would need to be entered into phpMyAdmin like this:

```
DELIMITER $$
CREATE TRIGGER Update_trigger
BEFORE INSERT ON product_price
FOR EACH ROW

BEGIN
    IF (NEW.product_id = 'P9999') 
    
    THEN SET NEW.product_id = 'name99', NEW.value_price = 999;
    END IF;
    
    IF (NEW.product_id = 'P7777') 
    THEN SET NEW.product_name = 'name77', NEW.value_price = 777;
    END IF;   
END$$
DELIMITER ;
```

But again, as I said, I am no expert, so please take all that has been said in this post with a pinch of salt.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.