How to lock a specific row that doesn't exist yet in SQL Server
问题 I have an API rate limit table that I'm managing for one of our applications. Here's the definition of it. CREATE TABLE [dbo].[RateLimit] ( [UserId] [int] NOT NULL, [EndPointId] [smallint] NOT NULL, [AllowedRequests] [smallint] NOT NULL, [ResetDateUtc] [datetime2](0) NOT NULL, CONSTRAINT [PK_RateLimit] PRIMARY KEY CLUSTERED ([UserId] ASC, [EndPointId] ASC) ) ON [PRIMARY] The process that performs CRUD operations on this table is multi-threaded, and therefore careful consideration needs to be