???SQL Server???????????????????????????
?????Jeffcky ???????[ 2017/5/27 11:18:48 ] ????????SQL Server ?????
???????
??????????????????????????????????????????????д????????????????????????????????????????????м??????????SQL Server?й??????????????????е???????е??????????д???????????????????
????SQL Server???????????????????
???????????????ж????????????????????儼???????????儼??????????????????????????????????????????????????????????????????????????????????????????????????????????????????ú????o?????????????????????????????????????????????????
CREATE TABLE Test (
Id INT IDENTITY(1?? 1) NOT NULL PRIMARY KEY??
Other VARCHAR(100))
GO
????????????????????????????
DECLARE @counter INT
SELECT @counter = 1
WHILE (@counter <= 10)
BEGIN
INSERT INTO Test
(Other)
SELECT 'other action' + CAST(@counter AS VARCHAR)
SELECT @counter = @counter + 1
END
?????????????????????????????SQL???
DECLARE @queueid INT
BEGIN TRAN TRAN1
SELECT TOP 1 @queueid = Id
FROM Test
PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)
WAITFOR DELAY '00:00:10'
DELETE FROM Test
WHERE Id = @queueid
COMMIT
??????????????????????????????????????С?
??????????????????????????????????????????????????????????????SQL Server????????????????????????????????????????????Ч?????????????м?????????????????????£?
DECLARE @queueid INT
BEGIN TRAN TRAN1
SELECT TOP 1 @queueid = Id
FROM Test WITH (updlock)
PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)
WAITFOR DELAY '00:00:10'
DELETE FROM Test
WHERE Id = @queueid
COMMIT
???????????????????????????????????????????????????????????????????????????????е???????????????????????????????????????????????????????????SQL Server????????READPAST???????????SQL Server???????????????????У??????????????????????????????????????????????????£?
DECLARE @queueid INT
BEGIN TRAN TRAN1
SELECT TOP 1 @queueid = Id
FROM Test WITH (updlock)
BEGIN TRAN TRAN1
SELECT TOP 1 @queueid = Id
FROM Test WITH (UPDLOCK?? READPAST)
PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)
WAITFOR DELAY '00:00:10'
DELETE FROM Test
WHERE Id = @queueid
COMMIT
PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)
WAITFOR DELAY '00:00:10'
DELETE FROM Test
WHERE Id = @queueid
COMMIT
???????UPDLOCK+READPAST?????y?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????£?
SET NOCOUNT ON
DECLARE @queueid INT
WHILE (SELECT COUNT(*) FROM Test WITH (updlock?? readpast)) >= 1
BEGIN
BEGIN TRAN TRAN1
SELECT TOP 1 @queueid = Id
FROM Test WITH (updlock?? readpast)
PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)
WAITFOR DELAY '00:00:10'
DELETE FROM Test
WHERE Id = @queueid
COMMIT
END
???????
????????????????????????SQL Server????β??????????????????????????????????????????????????????????????????кθ????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11