How to create an AUTOMATIC number in Teradata SQL

I want to create an AUTOMATIC Number to use TD SQL, for example, as follows:

CREATE MULTISET TABLE TEST_TABLE
(
  AUTO_NUMBER INT,
  NAME VARCHAR(10)
)
PRIMARY INDEX (AUTO_NUMBER);

INSERT INTO TEST_TABLE
VALUES('TOM');
INSERT INTO TEST_TABLE
VALUES('JIM');
INSERT INTO TEST_TABLE
VALUES('JAN');

SELECT * FROM TEST_TABLE;

The result will be higher

1 TOM
2 JIM
3 JAN
+3
source share
2 answers

Create a column with the syntax below:

SEQ_NUM decimal(10,0) NOT NULL GENERATED ALWAYS AS IDENTITY
           (START WITH 1 
            INCREMENT BY 1 
            MINVALUE 1 
            MAXVALUE 2147483647 
            NO CYCLE)
+3
source

Usually there is a column in a unique table.

You can use the method below to add a column to your result set if you do not want to add an additional column to your table.

select RANK () OVER (ORDER BY), T. * SEQ from table T;

This will give you the output, for example:

1 a xx yy 2 b xx yy 3 c xx yy

0
source

All Articles