Attempts to lock one or more records in a table.

LOCK([nWorkArea | cTableAlias]|
 [cRecordNumberList, nWorkArea | cTableAlias])


nWorkArea| cTableAlias

Attempts a lock on the current record in a table open in a specific work area. nWorkArea specifies the work area number and cTableAlias specifies the table alias. If you do not specify a work area or table alias, LOCK( ) attempts to lock the current record in the table in the current work area.


Specifies a list of one or more record numbers which you must include to attempt to lock multiple records. SET MULTILOCKS must be ON and you must include the work area or alias of the table for which you are attempting to place multiple record locks.

LOCK( ) attempts to lock all of the records you specify. The record numbers specified with cRecordNumberList are separated by commas. For example, to attempt record locks on the first four records in a table, cRecordNumberList must contain 1,2,3,4.

You can also lock multiple records by moving the record pointer to the record you would like to lock, issuing LOCK( ) or RLOCK( ) and then repeating these steps for each additional record.

In Visual FoxPro, you can specify 0 as a record number. Specifying 0 makes it possible for you to attempt to lock the table header.


Keep the table header locked for as short a time as possible because other users cannot add records to the table when the table header is locked.

Release the table header lock with UNLOCK RECORD 0, UNLOCK or UNLOCK ALL.

If all the records specified in cRecordNumbers are successfully locked, LOCK( ) returns true (.T.). If even one of the records specified with cRecordNumbers cannot be locked, LOCK( ) returns false (.F.) and none of the records are locked. However, any existing record locks remain in place. Multiple record locking is an additive process. Placing additional record locks does not release locks on other records.

The maximum number of records that can be locked in each work area is approximately 8,000. It is always faster to lock the entire table rather than even a small number of records.

Expand imageReturn Value

Expand imageRemarks

Expand imageExample

Expand imageSee Also