My teacher sent me this code, we are doing mysql, last time she sent oraclesql code, so this might be oraclesql:
CREATE TRIGGER Kontrola
ON DATABASE
FOR DROP_TABLE, ALTER_TABLE
AS PRINT "Brisanje i izmena nad objektima nije dozvoljena!"
ROLLBACK
And it says:
#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 'ON IZVRSIOCI
AFTER INSERT
AS BEGIN
PRINT 'Novi zapis u tabeli'
END' at line 2
I am getting an error in my mySql query when i execute my create trigger query in mysql using phpmyadmin which is provided below.
Error:
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
MySql Query:
CREATE TRIGGER Trigger_INSERT_club_app_member_contact_info After INSERT ON club_app_member_contact_info
FOR EACH ROW
BEGIN
INSERT INTO club_app_events_list(type_id,event_title,event_description,event_date,event_time,event_venue)
values(1,CONCAT('Happy Birthday ',NEW.title,NEW.name),NEW.mobile_no,NEW.dob,'8.30AM','');
IF NEW.ismarried == 'Yes' THEN
INSERT INTO club_app_events_list(type_id,event_title,event_description,event_date,event_time,event_venue)
values(1,CONCAT('Happy Birthday ',NEW.title_for_spouse,NEW.nameOf_spouse,'Spouse of (',NEW.title,NEW.name,')'),NEW.spouse_mobileNo,NEW.spouse_dob,'8.30AM','');
INSERT INTO club_app_events_list(type_id,event_title,event_description,event_date,event_time,event_venue)
values(2,CONCAT('Happy Wedding Anniversary to ',NEW.title,NEW.name ,' & ',NEW.title_for_spouse,NEW.nameOf_spouse),NEW.mobile_no,NEW.weeding_date,'8.30AM','');
END IF
END
I don't know what's wrong with my query.Can anyone help me to find a solution.
Few thing i noticed IF NEW.ismarried == 'Yes' THEN it should IF NEW.ismarried = 'Yes' THEN BEGIN and END IF should end with semicolon ; although BEGIN end enclose END;
But since i am trying to execute this query using phpmyadmin I have to remove Delimiter from the bottom text box of phpmyadmin.
But note that this is only phpmyadmin analysis warnings not a mysql server response.
I want to add a trigger in my database in phpmyadmin to rollback an insertion into the table if a particular attribute is greater than 100.
Here is my code that I wrote in the window for define in the "Add Trigger" window:
BEGIN
ROLLBACK IF NEW.max_allowed > 100
END;
I am getting this error:
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 'IF NEW.max_allowed > 100 END' at line 2
Can someone please suggest what I'm missing?
ROLLBACK can't be used together with IF in the same statement.
Check the documentation.
I suggest this code for your trigger:
BEGIN
IF NEW.max_allowed > 100 THEN
ROLLBACK;
END IF;
END;
i'm trying to create a trigger on my database but i'm getting this error "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 " but i can't understand why. This is the query:
CREATE TRIGGER cancella_associativa AFTER DELETE ON libro
FOR EACH ROW
BEGIN
DELETE FROM annuncio_autore
WHERE libro.`idLibro` = annuncio_autore.`idAnnuncio`;
END
Using phpMyAdmin, thanks in advance.
The ; after the line that contains WHERE ends your (incomplete) CREATE TRIGGER query. You need to change the delimiter:
delimiter //
CREATE TRIGGER ... //
delimiter ;
For more information see MySQL manual.
DELIMITER ||
CREATE TRIGGER `monthly_insert` BEFORE INSERT ON `history_monthly`
FOR EACH ROW
BEGIN
NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);
END;
||
DELIMITER ;
And it returns 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 '.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);
END' at line 4
It's my first time with triggers and I was doing my best to try to find soultion but I failed ;<
You need to add the word SET in this line:
SET NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);
Also, as the commenter pointed out, there is no OLD value in a BEFORE INSERT trigger.