Results 1 to 2 of 2

Thread: Trigger Syntax

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Unanswered: 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

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •