Can someone tell me what this sql does not work? Where is the syntax error?
SET NEW.`modified` = CURTIME() WHERE `id` = NEW.id;
Error:
One or more errors have occured while processing your request:
The following query has failed:
CREATE DEFINER=`root`#`localhost` TRIGGER `event_name`
BEFORE UPDATE ON `clients`
FOR EACH ROW
SET NEW.`modified` = CURTIME() WHERE `id` = NEW.id;
MySQL said: #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 'WHERE id = NEW.id' at line 1
Image shows the error
http://s23.postimg.org/rhsf2x1tn/screenshot.png
You don't need the where condition to specify the row being changed.
For every row being updated, you set the specific column value. See the example below as well as the quoted reference.
Quoting/Referencing from here:
DELIMITER |
CREATE TRIGGER event_name BEFORE UPDATE ON clients
FOR EACH ROW
BEGIN
SET NEW.date_modify = NOW();
END;
|
DELIMITER ;
Related
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 ;
Here is my trigger, I am getting the MySQL syntax error. I wanted to reduce the balance from sms_index table sms_count column value.
CREATE TRIGGER sms_log_update AFTER UPDATE ON sms_index
FOR EACH ROW
BEGIN
IF NEW.approved_status = '1' THEN
UPDATE sms_package SET balance = (balance - OLD.sms_count) WHERE group_id = OLD.ins_group_id;
END IF;
END;
Error Message:
#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
Your code looks correct, except for the possible problem of the delimiter. Try the following:
DELIMITER //
CREATE TRIGGER sms_log_update AFTER UPDATE ON sms_index
FOR EACH ROW
BEGIN
IF NEW.approved_status = '1' THEN
UPDATE sms_package SET balance = (balance - OLD.sms_count)
WHERE group_id = OLD.ins_group_id;
END IF;
END;//
DELIMITER ;
From the documentation:
However, just as for stored routines, if you use the mysql program to define a trigger that executes multiple statements, it is necessary to redefine the mysql statement delimiter so that you can use the ; statement delimiter within the trigger definition.
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.
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.
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.