Results 1 to 3 of 3

Thread: Trigger update?

  1. #1
    Linkan Guest

    Trigger update?


    Hello, I have two tables, looks as follow.

    TOPIC
    ------
    TOPIC_ID
    STATUS_ID
    TOPIC


    THREAD
    -------
    THREAD_ID
    TOPIC_ID
    STATUS_ID
    THREAD
    THREAD_DATE
    NAME

    I want to update STATUS_ID in TOPIC when I post a new THREAD.
    I guess the best would be to use a trigger?
    Don't know much how you write them so if someone please could help or point me in right direction.
    My plan is to always show the updated STATUS_ID in TOPIC while I have history in the THREAD TBL.
    I am using MS SQL 7.0

    Thanks for a great site.

    Linkan

  2. #2
    Jim W Guest

    Trigger update? (reply)

    You could also just use a stored procedure that handles the insert of the new thread and the update of the topic table.

    A trigger isn't a bad method to use on this though. But if you want to use it, read up on triggers in books online. Not trying to be brusque, but you'll get a better handle on it that way.

    ------------
    Linkan at 2/21/01 3:02:24 PM


    Hello, I have two tables, looks as follow.

    TOPIC
    ------
    TOPIC_ID
    STATUS_ID
    TOPIC


    THREAD
    -------
    THREAD_ID
    TOPIC_ID
    STATUS_ID
    THREAD
    THREAD_DATE
    NAME

    I want to update STATUS_ID in TOPIC when I post a new THREAD.
    I guess the best would be to use a trigger?
    Don't know much how you write them so if someone please could help or point me in right direction.
    My plan is to always show the updated STATUS_ID in TOPIC while I have history in the THREAD TBL.
    I am using MS SQL 7.0

    Thanks for a great site.

    Linkan

  3. #3
    Linkan Guest

    Trigger update? (reply)

    Thanks for your input, I have done some reading in books online and I managed to insert in TOPIC with a trigger fired when a new thread is inserted. I just don't seem to get the UPDATE work. There can be many threads to a topic but I always want to have the latest status_id the TOPIC table.
    Following code shows how the trigger looks when it insert.

    CREATE TRIGGER [trg_Update_Status] ON tForumThread
    FOR INSERT
    AS
    INSERT INTO
    tJournalTopic (STATUS_ID)
    SELECT STATUS_ID
    FROM Inserted

    Thanks
    //Linkan


    ------------
    Jim W at 2/21/01 3:14:08 PM

    You could also just use a stored procedure that handles the insert of the new thread and the update of the topic table.

    A trigger isn't a bad method to use on this though. But if you want to use it, read up on triggers in books online. Not trying to be brusque, but you'll get a better handle on it that way.

    ------------
    Linkan at 2/21/01 3:02:24 PM


    Hello, I have two tables, looks as follow.

    TOPIC
    ------
    TOPIC_ID
    STATUS_ID
    TOPIC


    THREAD
    -------
    THREAD_ID
    TOPIC_ID
    STATUS_ID
    THREAD
    THREAD_DATE
    NAME

    I want to update STATUS_ID in TOPIC when I post a new THREAD.
    I guess the best would be to use a trigger?
    Don't know much how you write them so if someone please could help or point me in right direction.
    My plan is to always show the updated STATUS_ID in TOPIC while I have history in the THREAD TBL.
    I am using MS SQL 7.0

    Thanks for a great site.

    Linkan

Posting Permissions

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