If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Trigger Syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-06-11, 07:49
jonhalton jonhalton is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
Trigger Syntax

Hi

I am new to using triggers but would like to set one up so was hoping for some help.

I have two related tables Forumpost and ForumReply.

What I would like to achieve is that when a new record is inserted into the ForumReply table the ForumPost table is updated with the current datetime.

I want to do this at row level and use the ForumPostID field of the newly inserted record in forum reply to select which record to update in forumpost.

The tables are as follows:

ForumPost
----------
ForumPostID
ForumPostMessage
DateUpdated - This is the field I want updating

ForumReply
-----------
ForumReplyID
ForumReplyMessage
ForumPostID - This is the field that links to ForumpostId in ForumPost table.

Any help to get me started would be helpful

Thanks

Jon
Reply With Quote
  #2 (permalink)  
Old 06-06-11, 09:33
jonhalton jonhalton is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
Worked it out

Hi

I think I have worked it out. this seems to work, in case anyone else has the same problem:

CREATE TRIGGER `UpdateDate` AFTER INSERT ON `forumreply` FOR EACH ROW Update forumpost
Set forumpost.UpdatedDate = Now()
Where new.PostID = PostID
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On