Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 mysql problem

Author  Topic 

Keshaba
Yak Posting Veteran

52 Posts

Posted - 2011-06-21 : 09:34:15
Hi i am creating a trigger in mysql as given below but it is giving me errors 'Can't update chat_master in stored function / trigger because it is already used by statement which invoked this stored procedure trigger


delimiter $
CREATE TRIGGER myTrigger
After INSERT ON chat_master
FOR EACH ROW
BEGIN
DECLARE row_count INTEGER;

SELECT COUNT(*)
INTO row_count
FROM chat_master
WHERE UM_master_id=NEW.UM_master_id;
IF row_count > 0 THEN
delete from chat_master where UM_master_id=1;
END IF;
end $$

Can anybody help

Keshab

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-21 : 10:11:21
In sql server you would generate an error/rollback the transaction to abort the update.
Why do you want to delete the row with UM_master_id=1? It says that's the row being inserted (or one of them) I think.
Does mysql have the concept of instead of or before triggers?

Isn't that if statement a waste of time? The current row will be in the table so row_count will always be at least 1.
Could be an if exists to save the count.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -