SELECT…FOR UPDATE

The SELECT…FOR UPDATE statement in Oracle is used primarily when an application needs to issue a positioned update or delete on a cursor by using the WHERE CURRENT OF syntax. In this case, optionally remove the FOR UPDATE clause, because Microsoft SQL Server cursors are updatable by default.

By default, SQL Server cursors do not hold locks under the fetched row. SQL Server uses an optimistic concurrency strategy to prevent updates from overwriting each other. If one user attempts to update or delete a row that has been changed since it was read into the cursor, SQL Server issues an error message. The application can trap this error message and retry the update or delete as appropriate. To override this behavior, developers can use SCROLL_LOCKS in a cursor declaration.

The optimistic concurrency strategy supports higher concurrency in the usual case in which collisions between updaters are rare. If your application really needs to ensure that a row cannot be changed after it is fetched, use the UPDLOCK hint in your SELECT statement. This hint does not block other readers, but it prevents other potential writers from also obtaining an update lock on the data. When using ODBC, you can achieve this effect by using SQLSETSTMTOPTION (…,SQL_CONCURRENCY)= SQL_CONCUR_LOCK. Either of these options reduces concurrency, however.