SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 mysql problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Keshaba
Yak Posting Veteran

India
52 Posts

Posted - 06/21/2011 :  09:34:15  Show Profile  Send Keshaba a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 06/21/2011 :  10:11:21  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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.

Edited by - nigelrivett on 06/21/2011 10:11:54
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000