MySQL - Create trigger error 1064 near line 1 - mysql

I'm trying to create a new trigger on a MySQL 8.0 database.
I get the following error when applying via MySQL Workbench...
ERROR 1064: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 1
Here is the trigger script...
DROP TRIGGER IF EXISTS tr_set_location_engagement;
DELIMITER $$
CREATE TRIGGER tr_set_location_engagement
BEFORE INSERT ON v2_nc_nip_cap_engagement
FOR EACH ROW
BEGIN
SET NEW.water_system_id = (SELECT water_system_id FROM v2_nc_registered_water_systems WHERE NEW.system_name = water_system_name);
SET NEW.province_id = (SELECT province_id FROM v2_nc_province WHERE NEW.province_name = province_name);
SET NEW.island_id = (SELECT island_id FROM v2_nc_island WHERE NEW.island_name = island_name);
SET NEW.area_council_id = (SELECT area_council_id FROM v2_nc_area_council WHERE NEW.area_council_name = area_council_name);
END $$
DELIMITER ;
Any help is deeply appreciated.

Thanks for all your help folks. The issue was that I was using the Trigger (Object) editor in MySQL Workbench to apply the trigger. When I applied the trigger using the SQL IDE in Workbench, the trigger was applied successfully.

Related

mySQL IF statement in trigger error in Maria DB

This code works fine in fiddle to create the trigger.
https://topanswers.xyz/databases?q=1929
However, I have the exact same code on my phpMyaAmin SQL command, but on phpMyAdmin return this in the create trigger section.
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;
#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?

create trigger not working in mysql

i am trying to write a trigger which validates insert statements before inserting in the table
table structure:
This is the code that i wrote
DELIMITER
$$
CREATE TRIGGER check_date_format
INSERT BEFORE ON
job_histry FOR EACH ROW
BEGIN
SET #bool=NEW.end_date LIKE '--/--/----';
IF #bool THEN
INSERT
INTO
job_histry
VALUES(
NULL,
NEW.start_date,
NEW.end_date,
NEW.job_id,
NEW.department_id
) ;
END IF ;
END
$$
This is the error that i received:
#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 'INSERT BEFORE ON job_histry FOR EACH ROW BEGIN SET #bool=NEW.end_date LIKE '' at line 2
why is this happening?
I am using localhost xampp server.
You have the trigger type (INSERT) and time (BEFORE) in the wrong order.
It should read
BEFORE INSERT ON job_histry

Error MySQL Creating Trigger

I'm getting an odd error every time I try to create one UPDATE trigger into one of my tables...
The Trigger:
CREATE TRIGGER upd_data_nascimento BEFORE UPDATE ON pfi_pessoa_fisica
FOR EACH ROW
BEGIN
IF OLD.date_of_birth = '0000-00-00' THEN
SET NEW.date_of_birth = NULL;
END IF;
END;
And the error:
Error SQL (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5
Any ideas?
Make sure you are using delimiter
CREATE TRIGGER upd_data_nascimento BEFORE UPDATE ON abc_table
FOR EACH ROW
BEGIN
IF OLD.date_of_birth = '0000-00-00' THEN
SET NEW.date_of_birth = NULL;
END IF;
END
If you are executing it in PHPMyAdmin then set the delimiter to # or something else. And then execute it will work fine I have tested it with above code.

Error when creating mysql trigger

I want to create a trigger to set the value of f_IrrMinCurr based on the IrrMinCurr. This is what I wrote.
CREATE TRIGGER Fuzzification BEFORE INSERT ON fuzzyanalysis
FOR EACH ROW
BEGIN
IF NEW.IrrMinCurr < 200.0 THEN
SET NEW.f_IrrMinCurr = 'H';
ELSE
SET NEW.f_IrrMinCurr = null;
END IF;
END;
I'm getting the error,
Error
SQL query:
CREATE TRIGGER Fuzzification BEFORE INSERT ON fuzzyanalysis
FOR EACH ROW
BEGIN
IF NEW.IrrMinCurr < 200.0 THEN
SET NEW.f_IrrMinCurr = null;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5
Can anyone please help me to solve this.

Auto update/fill a DATETIME column in MySQL using a trigger

I'm trying to auto update/fill datetime columns in my database.
I'm current running:
MYSQL server: 5.1.56-log
MySQL client version: mysqlnd 5.0.10
I've created two triggers based on the documentation (http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html):
INSERT TRIGGER:
create trigger 'games_insert'
before insert
on games for each row
begin
set new.created = NOW();
set new.modified = NOW();
end;
MODIFICATION TRIGGER
create trigger 'games_update'
before update
on games for each row
begin
set new.modified = NOW();
end;
Both seem to be valid since you can only modify the new row prior to updating/inserting. The AFTER yields many more errors.
However, I keep getting the following syntax error and I'm not sure why:
1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near ''games_insert' before insert on games for each row
begin set new.created =' at line 1
I'm interacting with the sql server through phpmyadmin and have set the delimiter to be $$
don't use "'" in trigger name
create trigger 'games_insert' (X)
create trigger games_insert (O)