Share via

blocking due to cuncurrency problem.

Rajesh Kumar Yadav 20 Reputation points
2024-06-10T06:08:53.8766667+00:00

hi,

I have a table "bridge"  where i keep bridgeid as pk , and hardly four to 5 rows are there

CREATE TABLE [dbo].[bridge](

bridgeid [bigint] NOT NULL,

[idpool] bigint NULL

CONSTRAINT [PK_bridge] PRIMARY KEY CLUSTERED

(

[bridgeid] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

Go

idPool col has number like 1 we increment it and use it as id pool like so.

this query is in small sp.

DECLARE @intID BIGINT ,@BRIDGID BIGINT=1

SELECT @intID = (idPool + 1)FROM IdConfiguration WHERE BRIDGID = @BRIDGID AND Status = 1

UPDATE BRIDGE SET idPool = idPool + 1, idPool = @intID WHERE BRIDGID = @BRIDGID AND Status = 1

Q1) the problem is the query blocks the whole table and in other transaction if i pass 2 in @BRIDGID

then also it is blocked by the first query where i have passed 1 in @BRIDGID.

yours sincerly

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


2 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 31,621 Reputation points
    2024-06-11T03:19:26.7666667+00:00

    Hi @Rajesh Kumar Yadav

    if i pass 2 in @BRIDGID then also it is blocked by the first query where i have passed 1 in @BRIDGID.

    Please check if exists any constraints (such as unique constraints or foreign key constraints) on the columns being updated. Ensure that the value being set doesn't violate any constraints.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Olaf Helper 47,621 Reputation points
    2024-06-10T08:50:49.3366667+00:00

    I don't understand your problem?

    That short UPDATE statement may block the table for a millisecond (and less).

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.