17.05 - Example: NOWAIT Option - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

You have a request that you do not want to be placed in the lock queue if it cannot be serviced immediately. In this case, use the NOWAIT option. For example:

     LOCKING employee FOR READ NOWAIT
     SELECT employee_number,  last_name
     FROM employee
     WHERE department_number=401;

     *** Failure 7423 Object already locked and NOWAIT.
            Transaction Aborted. Statement# 1, Info =0

Another request had employee locked, so you must resubmit the request.

     LOCKING employee FOR READ NOWAIT
     SELECT employee_number, last_name
     FROM employee
     WHERE department_number=401;

      *** Query completed. 7 rows found. 2 columns returned.
      *** Total elapsed time was 1 second.
     employee_number  last_name
     ---------------  --------------------
                1003  Trader
                1004  Johnson
                1013  Phillips
                1002  Brown
                1010  Rogers
                1022  Machado
                1001  Hoover

This time, no locks were being held on employee, so the request completed successfully.