Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Version: Available or changed with runtime version 1.0.
Starts locking on a table to protect it from write transactions that conflict with each other.
Syntax
Record.LockTable([Wait: Boolean] [, VersionCheck: Boolean])
Parameters
Record
Type: Record
An instance of the Record data type.
[Optional] Wait
Type: Boolean
Specifies what to do if the table is already locked. If this parameter is true and if another application has already locked the table, the system will wait until the table is unlocked. If this parameter is false and if another application has already locked the table, a run-time error occurs.
[Optional] VersionCheck
Type: Boolean
If this parameter is true, the version of the Record will be checked. If this parameter is false, blank, or not used, the version will not be checked.
Remarks
Read scale-out lets databases offload read-only workloads to read-only replicas, isolating them from the main read-write workload to improve performance. Learn more in Using read scale-out for better performance.
LockTable behaves differently depending on whether read scale-out is used. If the session doesn't use read scale-out, LockTable does these actions:
- Starts a transaction.
- Makes sure that all subsequent statements that read data apply an UPDLOCK on the database.
If the session uses Read Scale-Out, LockTable does the following:
- Makes sure that all subsequent statements that read data use REPEATABLEREAD on the database.
Because all write operations automatically lock the table that is being used, LockTable would appear unnecessary. However, you could have a transaction in which an application wants to inspect data before possibly changing it, with a guarantee that the data being changed has not been modified by other applications since the read operation. The solution is to explicitly lock the table before the read operation. This makes sure that no other application makes changes between the read operation and the possible write operation.
The table lock is released (unlocked) when the transaction is committed.
This method works the same as the RecordRef LockTable Method.
Related information
Record Data Type
Get Started with AL
Developing Extensions
AL Database Methods and Performance on SQL Server