CREATE TRIGGER Tr1
AFTER DELETE ON Table1
REFERENCING
OLD TABLE AS OldTable,
NEW TABLE AS NewTable
FOR EACH STATEMENT
Produces the following 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 'REFERENCING
OLD TABLE AS OldTable,
NEW TABLE AS NewTable
Why is this?
If you want to view old table, then you should create BEFORE DELETE trigger -
CREATE TRIGGER Tr1
BEFORE DELETE
ON Table1
FOR EACH ROW
BEGIN
...
SET #old_count = NULL;
SELECT COUNT(*) INTO #old_count FROM Table1;
...
END
Related
I am trying to add a trigger, when a table is updated (except for two columns in that table), it updates another table. The query I used is given below:
CREATE TRIGGER my_trigger
BEFORE UPDATE ON town_1a2b3c4d
BEGIN
IF NOT UPDATE (is_killed) AND NOT UPDATE (is_executed)
BEGIN
UPDATE town_details SET game_index = game_index + 1 WHERE town_id = '1a2b3c4d';
END;
END;
But it gives me 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 'BEGIN
IF NOT UPDATE (is_killed) AND NOT UPDATE (is_executed)
BEGIN...' at line 3
How to Update table1 if the table1 primary key existing in table2. I am using following code but it gives mysql syntax error.
CREATE TRIGGER upd_selectoin
BEFORE UPDATE ON customer
FOR EACH ROW
BEGIN
IF NEW.customer_sk IN(SELECT quotation_cname FROM quotation) THEN
UPDATE customer s JOIN quotation m
ON m.quotation_cname = s.customer_sk
SET s.grade = 2
WHERE s.customer_sk = NEW.customer_sk;
END IF;
I got the following 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 '' at line 9
I want to update the customer table grade column if the customer_sk existing in quotation table.Please help me
This is working:
select * FROM Work_Request A where EXISTS ( select 1 from Customer B where (B.lsource&128)!=0 and B.license_id=A.license_id) ;
As per Delete all rows in a table based on another table this delete should also work but instead giving error:
delete FROM Work_Request A where EXISTS ( select 1 from Customer B where (B.lsource&128)!=0 and B.license_id=A.license_id) ;
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 'A where EXISTS ..
...
your delete statement should be like this
delete A.* FROM Work_Request A
where EXISTS ( select 1 from Customer B where (B.lsource&128)!=0 and B.license_id=A.license_id) ;
you are missing name of table thats gonna delete ...have fun :-)
I have a table named sample_table and its columns are col_a, col_b, col_c.
I am trying to create a trigger in MySQL 5.6 which will update col_c(as concat(col_a,col_b)) on insertion of a row. Query which I have written for this is:
create trigger trg_sample_table
after insert on sample_table
for each row
begin
set col_c=concat(col_a,col_b)
end;
While running this sql, the error I am getting is:
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 'end' at line 6.
Could any one of you please help me to create a trigger as I need?
You need to make it a before insert. Try this:
create trigger trg_sample_table before insert on sample_table for each row
begin
set new.col_c=concat(new.col_a,new.col_b);
end;
You cannot modify the row that you just inserted in an after insert trigger. If you want to modify it, it needs to be done in a before insert.
I'm trying to create a trigger that monitor changes on a table and then insert those change to another table as follows
CREATE TRIGGER userChangePasswd
BEFORE UPDATE ON originalTable
FOR EACH ROW
BEGIN
INSERT INTO logs (email,clear,name ) SELECT email,clear,name FROM originalTable
END
mysql keeps showing the following 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 'INSERT INTO logs (email,clear,name ) SELECT email,clear,name FROM ' originalTable at line 5
the following statement works very file with a where clause criteria
INSERT INTO logs (email,clear,name ) SELECT email,clear,name FROM originalTable
what's wrong with the insertion statement within the trigger
CREATE TRIGGER `orgTbl_before_upd_tr` BEFORE UPDATE ON `orgTbl`
FOR EACH ROW
BEGIN
INSERT INTO newTbl (field1, field2) VALUES (old.field1, old.field2);
END;