Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate AUTOMATIC Number in Teradata SQL

I want to generate 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 above will be ,

1 TOM
2 JIM
3 JAN
like image 865
user2002948 Avatar asked Feb 24 '14 08:02

user2002948


People also ask

How do I generate a number automatically in SQL?

The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature. In the example above, the starting value for IDENTITY is 1, and it will increment by 1 for each new record. Tip: To specify that the "Personid" column should start at value 10 and increment by 5, change it to IDENTITY(10,5) .

How does Teradata generate random numbers?

You can call RANDOM any number of times in the SELECT list, for example: SELECT RANDOM(1,50), RANDOM(1,100);

What is CSUM in Teradata?

The Cumulative Sum (CSUM) function provides a running or cumulative total for a column's numeric value. This allows users to see what is happening with column totals over an ongoing progression.

What is an identity column in Teradata?

Identity column is a way to generate system generated unique identifier for a table in Teradata.


1 Answers

Create a column with the below syntax:

SEQ_NUM decimal(10,0) NOT NULL GENERATED ALWAYS AS IDENTITY
           (START WITH 1 
            INCREMENT BY 1 
            MINVALUE 1 
            MAXVALUE 2147483647 
            NO CYCLE)
like image 122
Lenin Raj Rajasekaran Avatar answered Nov 01 '22 09:11

Lenin Raj Rajasekaran