Example: Creating a Queue with a UPI and a NUSI - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

This example creates a queue table with a UPI defined on the queue sequence number identity column, QSN, and a NUSI defined on the queue insertion timestamp, QITS:

    CREATE TABLE qtbl_5, QUEUE (
      qits  TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
      qsn   INTEGER GENERATED ALWAYS AS IDENTITY (NO CYCLE),
      col_3 INTEGER)
    UNIQUE PRIMARY INDEX (qsn)
    INDEX qits;

With a high rate of consumption of queue table rows, you typically replace the NO CYCLE option with CYCLE. CYCLE has the advantage of enabling the reuse of QSN numbers while not failing when MAXVALUE is exceeded. The UPI on QSN guarantee that the value of QSN is unique.