Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-10-2009
Member
 
Join Date: Jun 2009
Posts: 53
Updating a field when another get updated

I am currently in my spear "triggers" (it is the first one I created). I have a table with three fields.

Table: Test
name of fields: id/visible/date

My goal is to create a trigger that when seen up to 1, it makes an update to date by inserting the current date.

Here is my wrong code:

Code:
DELIMITER ^
CREATE TRIGGER UPDATE AFTER UPDATE ON test FOR EACH ROW
begin
  IF (NEW.etat=='1') then NEW.date=CURRENT_TIMESTAMP;
  end IF;
end^
DELIMITER ;
Could any one of you help me?
Reply With Quote
  #2  
Old 26-10-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Updating a field when another get updated

May be because you want to identify your trigger "update" and it's not like that? If what you have in fact is wrong then is there any error message?
Reply With Quote
  #3  
Old 26-10-2009
Member
 
Join Date: Jun 2009
Posts: 53
Re: Updating a field when another get updated

Thank you for your reply, I changed the name of the function "test". Same 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 '== 1) then NEW.DATE=CURRENT_TIMESTAMP;
Reply With Quote
  #4  
Old 26-10-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Updating a field when another get updated

There is no parenthesis around the condition of the IF. There to CURRENT_TIMESTAMP I know (trying to use a function rather than the variable), I think the problem is mainly to be used "SET foo = foo" and not directly "foo = foo".

In addition if you want to change the NEW line, must be in your trigger BEFORE UPDATE and AFTER UPDATE not.

You would do well even when reading the doc of MySQL, because all these answers are there.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Updating a field when another get updated"
Thread Thread Starter Forum Replies Last Post
Updating actual and remaining work from Excel not updating properly josocal Microsoft Project 1 13-02-2012 07:49 PM
Sync AD computer description field with local computer description field. Michael Windows Server Help 7 18-10-2011 01:05 AM
Fix a field on a LAN DNS Remedy Networking & Security 4 26-12-2009 03:01 PM
Multi Field value field in Microsoft Access Erubiel Windows Software 3 20-11-2009 12:55 AM


All times are GMT +5.5. The time now is 11:39 PM.