MySQL Forums
Forum List  »  Microsoft SQL Server

Re: Problem implementing creating trigger using MYSQL 5.0
Posted by: Roland Bouman
Date: October 31, 2005 02:42PM

Hi!

when you do this from the command line or query browser, first, set the delimiter to something other than the default, wich is the semicolon (;):

delimiter //

Now, the tool will wait for a // before it sends the commands to the server.

then, enter your statement, using the MySQL CREATE TRIGGER syntax. you can loook it up here:

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

CREATE TRIGGER
orders_update ON Orders
BEFORE INSERT ON Orders
FOR EACH ROW
BEGIN
..
..type your statements here.
..
END;

Now, as for the code within, I think i dont understand it entirely. First, I'm confused because you are calling the trigger orders_update. I'm think you mean 'update' in the informal sense, but to me, it's confusing in the context of triggers. I'd call it:

bir_orders

so you can immediately see the trigger is

Before Insert on orders for each Row

Now, the update you are issuing, is it meant to update the row that is being inserted? If so, you can just plug in the value directly into the NEW pseudo record.

MS SQL uses INSERTED and DELETED implicit tables (i dont know what for UPDATE triggers) wich possibly contain multiple rows. MySQL does not do this. MySQL triggers are always for each row, and you can reference the current row through the NEW (INSERT and UPDATE triggers) and OLD (DELETE and UPDATE triggers) pseudorecord.

So, to set the order_date, you could do:

set new.order_date := current_timestamp();

If this is the only thing you need the trigger to do, you better use a column of the TIMESTAMP datatype. This will automatically behave like this. Check it out:

http://dev.mysql.com/doc/refman/5.0/en/datetime.html

Options: ReplyQuote


Subject
Written By
Posted
Re: Problem implementing creating trigger using MYSQL 5.0
October 31, 2005 02:42PM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.