Mysql create trigger 1064 error - mysql

The sql i wrote
**delimiter |
CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id
END
|
delimiter ;**
The error given
[SQL]
**CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id
END
;
[Err] 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 'END' at line 6**
How to solve this ? where is the mistake i do ?

It looks like you simply need to terminate your UPDATE statement with a semicolon.

Try this code
delimiter |
CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id;
END;|
delimiter ;

Related

Syntax error during creation of trigger on mySQL 10.3.17-MariaDB-log version

I'm trying to add a trigger that should automatically update a datetime column only if is not present a SQL variable. The trigger code is the following
delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW
BEGIN
IF #disable_sync_date_update IS NULL OR #disable_sync_date_update <> 1 THEN
SET new.sync_date = CURRENT_TIMESTAMP
END IF
END|
delimiter ;
The error that I recieve is
#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 'END IF
END' at line 7
Thanks for helping
I've found the solution, here is the correct code:
delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW
BEGIN
IF #disable_sync_date_update IS NULL OR #disable_sync_date_update <> 1 THEN
SET new.sync_date = CURRENT_TIMESTAMP;
END IF;
END|
delimiter ;

MySQL IF statement in Trigger

I just want to create trigger in my sql but some error happened
this is the code
CREATE TRIGGER delete_santri_in_kamar
AFTER UPDATE ON
santri
FOR EACH ROW
BEGIN
DECLARE stat INT
SET stat = select status FROM santri WHERE id_santri=new.id_santri
IF (stat = 0) THEN
DELETE FROM santri_kamar_asrama WHERE id_santri=new.id_santri
END IF
END
and this is the error message
#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 'SET stat = select status FROM santri WHERE id_santri=new.id_santri
IF (stat =' at line 7
please help me
Add semicolons after the statements and change default delimiter(;) before the code of create trigger. Otherwise it will give
SQL Error(1064): You have an error in your SQL Syntax;
After the create trigger code make ; as default delimiter
DELIMITER $$
CREATE TRIGGER delete_santri_in_kamar
AFTER UPDATE ON
santri
FOR EACH ROW
BEGIN
DECLARE stat INT;
SET stat = (select status FROM santri WHERE id_santri=new.id_santri);
IF (stat = 0) THEN
DELETE FROM santri_kamar_asrama WHERE id_santri=new.id_santri;
END IF;
END
$$
DELIMITER ;

Error 1064 mysql syntax

I am new to Mysql and I am trying to write mysql stored procedure with transaction.but I am getting 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 21
Here is my procedure:
DELIMITER $$
CREATE PROCEDURE InsertVote(IN image_param VARCHAR(30),
IN user_id_param INT,
IN vore_char CHAR(1)
)
Begin
START TRANSACTION;
IF vote_char="A" THEN
UPDATE img_options SET A_result=(A_result+1) WHERE image=image_param;
ELSE IF vote_char="B" THEN
UPDATE img_options SET B_result=(B_result+1) WHERE image=image_param;
ELSE IF vote_char="C" THEN
UPDATE img_options SET C_result=(C_result+1) WHERE image=image_param;
ELSE
UPDATE img_options SET D_result=(D_result+1) WHERE image=image_param;
END IF;
Insert into WATCH_FEED_EVEN values(image_param,user_id_param);
select * from img_options where image=image_param;
COMMIT; <---Line No 21
END $$
DELIMITER ;
I tried to solve this one for more than 2 hours but I couldn't able to do this.Can anyone help me?

Error 1064 during trigger creation

I want to create a trigger on one of the tables, it's very simple, just to set one value - but I always get error 1064
CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table`
FOR EACH ROW
BEGIN
IF NEW.as_src = 13335 THEN
SET NEW.peer_as_src = 13335;
END IF
END
And get this 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 idea why ?
You need to change the default delimiter
delimiter |
CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table`
FOR EACH ROW
BEGIN
IF NEW.as_src = 13335 THEN
SET NEW.peer_as_src = 13335;
END IF;
END
|
delimiter ;
Otherwise the statement will end at the first ; which would make the trigger definition incomplete.

sql error on creating a trigger

I typed this code into mysql and it gave an error:
CREATE TRIGGER delete_vote_topic BEFORE DELETE ON vote_topic
FOR EACH ROW BEGIN
DELETE FROM vote_option WHERE vote_topic_id = OLD.id;
DELETE FROM vote_option_votes WHERE vote_topic_id = OLD.id;
END;
the error was:
#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 3
Anybody knows what I'm doing wrong?
Try using a delimiter
delimiter |
CREATE TRIGGER delete_vote_topic BEFORE DELETE ON vote_topic
FOR EACH ROW
BEGIN
DELETE FROM vote_option
WHERE vote_topic_id = OLD.id;
DELETE FROM vote_option_votes
WHERE vote_topic_id = OLD.id;
END;
|