MySql Triggers Error - mysql

I have 2 tables in MySql dealers and dealers_info. I try to create trigger which after deleting info from dealers will delete corresponding rows from dealers info
CREATE TRIGGER del_info AFTER DELETE ON dealers
FOR EACH ROW
BEGIN
DELETE FROM dealers_info WHERE dealer_id = OLD.dealer_id;
END;
But I've got an 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 4

change the delimiter to execute the query properly,
DELIMITER $$
CREATE TRIGGER del_info
AFTER DELETE ON dealers
FOR EACH ROW
BEGIN
DELETE FROM dealers_info WHERE dealer_id = OLD.dealer_id;
END $$
DELIMITER ;

Related

Trigger after insert MySQL for order data by date value

I wanna make tringger, so after inserting data, the datas ordered by date (here name 'tanggal')
but got error #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 'ORDER BY tanggal ASC;
END' at line 5
DELIMITER $$
CREATE TRIGGER sort_by_tanggal
AFTER INSERT ON laporan_bukubesar
FOR EACH ROW
BEGIN
ALTER TABLE laporan_bukubesar ORDER BY tanggal ASC;
END $$
DELIMITER ;

Trigger to update table based on another table update in mysql

I have two tables
1. Tag
2. Triger_testing
Tag desc
id int, is_active (tinyint)
Trigger_Testing Desc
tag_id (int), is_active(tinyint)
I want to create a trigger on tag table update which update trigger_testing table. So if tag.is_active is set to 0 the trigger must fire and update trigger_testing table and set trigger_testing.is_active=0 where trigger_testing.tag_id=tag.id.
I tried to create a trigger in MYSQL but getting syntax exception. Can someone help me out in resolving that issue.
Here is the code : -
CREATE TRIGGER update_trigger_testing AFTER UPDATE ON tag
FOR EACH ROW
BEGIN
IF NEW.is_active=0 THEN
UPDATE trigger_testing SET is_Active=0 WHERE tag_id=NEW.id
END IF
END$$
DELIMITER;
The error I am getting is :
Error Code: 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 IF
END$$
DELIMITER' at line 6
CREATE TRIGGER update_trigger_testing AFTER UPDATE ON tag
FOR EACH ROW
BEGIN
IF NEW.is_active=0 THEN
UPDATE trigger_testing SET is_Active=0 WHERE tag_id=NEW.id;
END IF;
END;

Error 1064 trying to create new trigger

I am trying to create a mysql trigger on delete to write a record on a history table but everytime 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 14
DELIMITER $$
USE `cedecapr_test`$$
CREATE
DEFINER=`root`#`localhost`
TRIGGER `mytable`.`users_delete`
BEFORE DELETE ON `mytable`.`users`
FOR EACH ROW
BEGIN
INSERT INTO `history_table_users`
VALUES
(
OLD.`username`
);
END$$
Any help will be appreciated. Thanks.

MySql on update trigger. Error of DELIMITER

I try to create trigger in MySql but get the following 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 'DELIMITER' at line 1
DELIMITER $$
CREATE TRIGGER library_update
AFTER UPDATE ON wq6vt_vehiclemanager_vehicles
FOR EACH ROW
BEGIN
INSERT IGNORE INTO wq6vt_vehiclemanager_library (maker, model) VALUES(NEW.maker, NEW.vmodel);
INSERT INTO wq6vt_vehiclemanager_library_data (co2_class)
SELECT co2_class FROM wq6vt_vehiclemanager_vehicles
WHERE maker = NEW.maker AND vmodel = NEW.vmodel;
END $$
DELIMITER;
The first query in the trigger do not lead to errors, but second one does. There is some problem with SELECT inside of INSERT ...I think so
there should be a space between the keyword and the symbol,
DELIMITER ;
-- ^ space in between here

mySQL Trigger returns error

I am trying to set up a trigger on a table to copy the contents of a row into another table.
I have the following:
CREATE TRIGGER story_deleted BEFORE DELETE ON stories
FOR EACH ROW BEGIN
INSERT INTO stories_backup SET story_id = OLD.story_id;
END;
This returns the following error though:
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
I can't work out where I'm going wrong with this. Any ideas?
Try changing the delimiter
DELIMITER $$
CREATE TRIGGER story_deleted BEFORE DELETE ON stories
FOR EACH ROW
BEGIN
INSERT INTO stories_backup SET story_id = OLD.story_id;
END $$
DELIMITER ;
and as far as your privileges go, run this query
SHOW GRANTS;
If SUPER is not there, you could
request your DBA to add that privilege for you
have your DBA create the trigger for you