我想将Table 的DriverID
列设置Driver
为 5000, 5001 ,....
为此,我编写了这个脚本:
use WeighbridgeDB
GO
DECLARE @NewDriverID int;
SET @NewDriverID = 5000;
DECLARE Driver_Cursor CURSOR FOR
SELECT DriverID FROM Driver
FOR UPDATE;
OPEN Driver_Cursor;
FETCH NEXT FROM Driver_Cursor
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Driver SET DriverID = @NewDriverID WHERE CURRENT OF Driver_Cursor;
SET @NewDriverID += 1;
FETCH NEXT FROM Driver_Cursor
END
CLOSE Driver_Cursor;
DEALLOCATE Driver_Cursor;
GO
但是 While 循环不会停止,并且值@@FETCH_STATUS
始终为 0。我认为 Cursor 会重建自身,因为更新发生在表或其他东西上。
如何纠正这种情况?
谢谢。