Hi,In an attempt to understand how can I update using CURSORS, I've tried the following code example:USE [AdventureWorks2]GODROP PROCEDURE HumanResources.UpdateAllEmployeeHireDateInefficientlyGOCREATE PROCEDURE HumanResources.UpdateAllEmployeeHireDateInefficiently ASBEGIN TRY SET XACT_ABORT ON DECLARE curemployee CURSOR FOR SELECT TOP 10 EmployeeID FROM HumanResources.Employee FOR UPDATE OPEN curemployee FETCH FROM curemployee WHILE @@FETCH_STATUS = 0 BEGIN UPDATE HumanResources.Employee SET HireDate = GETDATE() WHERE CURRENT OF curemployee FETCH FROM curemployee -- to avoid the output row, store it into variable END END TRY BEGIN CATCH ROLLBACK TRANSACTION PRINT 'An error occured, transaction rolled back' END CATCH COMMIT;GOEXEC HumanResources.UpdateAllEmployeeHireDateInefficiently
The code runs fine whether the "FOR UPDATE" keyword is used or not.what is the difference between when the "FOR UPDATE" keyword is used and when it isn't?Cheers,ozSQL