Example: INSERT and GENERATED BY DEFAULT Identity Columns - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-12-13
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantageā„¢

The result of inserting values into the same table defined in Example: INSERT and GENERATED ALWAYS Identity Columns shows the difference in the behavior of the two identity column types. Because GENERATED BY DEFAULT only generates values when an INSERT request does not supply them, the same insert operations produce different results.

Assume that column_1 of newly created table_1 is an identity column defined as GENERATED BY DEFAULT. The following INSERT requests generate numbers for column_1 of the inserted rows only if they do not specify a value for that column.

     INSERT INTO table_1 (column_1, column_2, column_3)
     VALUES (111,111,111);

     INSERT INTO table_1 (column_1, column_2, column_2)
     VALUES (,222,222);

Check the result of the insert operations by selecting all the rows from table_1.

     SELECT *
     FROM table_1;

Result:

     *** Query completed. 2 rows found. 3 columns returned.
     *** Total elapsed time was 1 second.
      column_1  column_2  column_3
     --------- --------- ---------
           111       111       111
             1       222       222