Getting Error #1064 Near End When Trying to Create a Trigger - mysql

DELIMITER $$
CREATE TRIGGER DELETETRIGGER AFTER DELETE ON WORKLOG
FOR EACH ROW
BEGIN
INSERT INTO WORKLOGCOPY (Log_ID, Order_ID, Employee_ID, Client_ID,
Work_Completed, Hours_Taken, Date_Logged)
VALUES(OLD.Log_ID, OLD.Order_ID, OLD.Employee_ID, OLD.Client_ID,
OLD.Work_Completed, OLD.Hours_Taken, OLD.Date_Logged)
END$$
DELIMITER ;
I am getting the 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
'END' at line 6
Have tried messing around with the syntax to match examples I have seen but with no luck.
Using MySQL on phpmyadmin if that helps.
Thank you.

You are missing ; at the end of INSERT INTO
DELIMITER $$
CREATE TRIGGER DELETETRIGGER AFTER DELETE ON WORKLOG
FOR EACH ROW
BEGIN
INSERT INTO WORKLOGCOPY (Log_ID, Order_ID, Employee_ID, Client_ID,
Work_Completed, Hours_Taken, Date_Logged)
VALUES(OLD.Log_ID, OLD.Order_ID, OLD.Employee_ID, OLD.Client_ID,
OLD.Work_Completed, OLD.Hours_Taken, OLD.Date_Logged);
END$$
DELIMITER ;

Related

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

MYSQL Creating Procedure

I am trying to create a procedure in MYSQL which just selects all the rows from a table.
DELIMITER $$
CREATE PROCEDURE getAll_Temps()
BEGIN
SELECT * from temp1
END $$
But I am getting this error,
ERROR 1064 (42000): 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.
Try below query.You miss the ; at the end of the query.
DELIMITER $$
CREATE PROCEDURE getAll_Temps()
BEGIN
SELECT * from temp1;
END $$
Hope this helpful to you.

SQL syntax error in mysql when creating trigger

I have a problem when creating a trigger in mysql i get this 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 7
This is my first time creating triggers for mysql help
Here is the code:
CREATE TRIGGER insertAfterUser AFTER INSERT ON MEMBERS
FOR EACH ROW
BEGIN
INSERT INTO blagajna (MemberId,StanjeRacuna) VALUES(12,0.0);
END;
You need to set the delimiter
delimiter //
CREATE TRIGGER insertAfterUser AFTER INSERT ON MEMBERS
FOR EACH ROW
BEGIN
INSERT INTO blagajna (MemberId,StanjeRacuna) VALUES(12,0.0);
END;//
delimiter ;
CREATE TRIGGER `insertAfterUser ` BEFORE INSERT ON `members` FOR EACH ROW BEGIN INSERT INTO blagajna (MemberId,StanjeRacuna) VALUES('12','0.0'); END;

Trigger, no inserting

Error
SQL query: Documentation
CREATE TRIGGER `triggers_div` AFTER INSERT ON `produits`
FOR EACH
ROW
BEGIN
INSERT INTO `div_extension` ( `devID` )
SELECT new.devID
FROM `produits`
WHERE new.depID =1;
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 somebody help me?
DELIMITER $$
CREATE TRIGGER triggers_div AFTER INSERT ON produits
FOR EACH
ROW
BEGIN
// SOME CODING HERE....
END ;$$
DELIMITER ;
It s work now when I add the DELIMITER like this DELIMITER $$ and not like this DELIMITER$$.

SQL trigger giving error

I'm trying to call a stored procedure to create multiple rows using some of the cell values of the new row inserted in the table resource but I'm getting an error. Here is my query:
CREATE TRIGGER `details` AFTER INSERT ON `resource`
FOR EACH ROW BEGIN
CALL addcopies(NEW.copies, NEW.id, NEW.location);
END;
#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
What am I doing wrong?
delimiter |
CREATE TRIGGER `details` AFTER INSERT ON `resource`
FOR EACH ROW BEGIN
CALL addcopies(NEW.copies, NEW.id, NEW.location);
END
|
delimiter ;
If you don't set another delimiter than ;, then the statement will end at the first ; and your trigger definition will be incomplete. You need to tell MySQL that the statement should end at the delimiter you defined. After that you can set the delimiter back with delimiter ;