Trigger for records Inserted/Updated at a time

  • Hi Folks

    I have the following 2 tables

    Assignment(wo#,laborcode) and Workorder(wo#,leadcraft)

    The data in both these tables is entered from the JSP frontend.

    Initially about 10-15 records are entered into wokrorder...and then the records are entered into Assignment for the corresponding wo# in one shot....

    It works fine...

    What I want is whenever a  record is inserted/updated  into a  assignment table the corresponding record in workorder table should  update...

    ie Suppose we have a Workorder(101,Cyril) ...

    Now when a new record  Assignment(101,John) in assignment table  the workorder table should become Workorder(101,John)...

    There can be many sumultaneous users on my frontend and each of then can attempt tp update 10-15 records at a time..

    I am trying to write a trigger for this.

    Can anyone  suggest me how do I achieve this without making my database unstable...

    Thanks for help


    Kindest Regards,

    Joel

  • CREATE TRIGGER TR_ASSIGNMENT_INSERT on dbo.Assignment

    FOR INSERT,UPDATE

    AS

    SET NOCOUNT ON

    UPDATE dbo.Workorder

    SET user=INSERTED.USER /*INSERTED CONTAINS NEW OR CHANGED DATA*/

    FROM dbo.Workorder Workorder

    inner join INSERTED /*LINK WITH WORKORDER*/

    ON INSERTED.WorkorderID=Workorder.ID

     

  • Hi Jo....

    Thanks for the reply.....But what if multiple records are inserted or updated at a time....Also there can be multiple users doing Multiple records Insert/Update Simultaneously

    Joel

     

     


    Kindest Regards,

    Joel

  • The trigger will fire once for each update statement and update every line modified by the query.

  • I am sorry if the question I am asking is too naive but I wanna be as safe as possible avoiding any damages to the database....

    Consider 2 users trying to update 10 records each in a batch simultaneously......

    Will it create any lock ot transaction related issue..

     

    Jol

     


    Kindest Regards,

    Joel

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply