how to avoid two updates hapens same table same time from two different procedures

  • Hello There,

    I have a procedure that is scheduled to run on sql server and some adhoc code that I am executing,

    both is kind of same logic but diferent purpose, here the problem is

    I have a table for get max(id) in the table then drives that id in the code (both places) here my code got updated each other

    how to avoid updating same table/ reading same table when the other table is reading it? please advise

    Thank you in advance

    please help me

    Milan

  • Instead of selecting the MAX(id) and then allocating it by insertin a row with that id, insert the row directly.

    -- Gianluca Sartori

  • If this ID is a sequential integer, then use IDENTITY.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • asita (10/12/2016)


    Hello There,

    I have a procedure that is scheduled to run on sql server and some adhoc code that I am executing,

    both is kind of same logic but diferent purpose, here the problem is

    I have a table for get max(id) in the table then drives that id in the code (both places) here my code got updated each other

    how to avoid updating same table/ reading same table when the other table is reading it? please advise

    Thank you in advance

    please help me

    Milan

    Use explicit transactions.

    The table will be locked for any updates until the transaction is committed or rolled back.

    _____________
    Code for TallyGenerator

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

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