Skip to content

Latest commit

 

History

History
89 lines (65 loc) · 3.5 KB

set-lock-timeout-transact-sql.md

File metadata and controls

89 lines (65 loc) · 3.5 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
SET LOCK_TIMEOUT (Transact-SQL)
SET LOCK_TIMEOUT (Transact-SQL)
WilliamDAssafMSFT
wiassaf
09/11/2017
sql
t-sql
reference
LOCK_TIMEOUT_TSQL
SET_LOCK_TIMEOUT_TSQL
SET LOCK_TIMEOUT
LOCK_TIMEOUT
timeout options [SQL Server], locks
releasing locks
LOCK_TIMEOUT option
SET LOCK_TIMEOUT statement
locking [SQL Server], time-outs
wait time for lock releases [SQL Server]
TSQL
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

SET LOCK_TIMEOUT (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw]

Specifies the number of milliseconds a statement waits for a lock to be released.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

SET LOCK_TIMEOUT timeout_period  

[!INCLUDEsql-server-tsql-previous-offline-documentation]

Arguments

timeout_period
Is the number of milliseconds that will pass before [!INCLUDEmsCoName] [!INCLUDEssNoVersion] returns a locking error. A value of -1 (default) indicates no time-out period (that is, wait forever).

When a wait for a lock exceeds the time-out value, an error is returned. A value of 0 means to not wait at all and return a message as soon as a lock is encountered.

Remarks

At the beginning of a connection, this setting has a value of -1. After it is changed, the new setting stays in effect for the remainder of the connection.

The setting of SET LOCK_TIMEOUT is set at execute or run time and not at parse time.

The READPAST locking hint provides an alternative to this SET option.

CREATE DATABASE, ALTER DATABASE, and DROP DATABASE statements do not honor the SET LOCK_TIMEOUT setting.

Permissions

Requires membership in the public role.

Examples

A: Set the lock timeout to 1800 milliseconds

The following example sets the lock time-out period to 1800 milliseconds.

SET LOCK_TIMEOUT 1800;  
GO  

Examples: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]

B. Set the lock timeout to wait forever for a lock to be released.

The following example sets the lock timeout to wait forever and never expire. This is the default behavior that is already set at the beginning of each connection.

SET LOCK_TIMEOUT -1;  

The following example sets the lock time-out period to 1800 milliseconds. In this release, [!INCLUDEssazuresynapse-md] will parse the statement successfully, but will ignore the value 1800 and continue to use the default behavior.

SET LOCK_TIMEOUT 1800;  

See Also

@@LOCK_TIMEOUT (Transact-SQL)
SET Statements (Transact-SQL)