5

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
Joe Taras
  • 15,166
  • 7
  • 42
  • 55
user2002948
  • 63
  • 1
  • 1
  • 4

2 Answers2

7

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)
Raj
  • 22,346
  • 14
  • 99
  • 142
-1

Usually there is a column in the table which is unique.

You can use below technique to add a column in your result set if you dont want to add extra column to your table.

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

It will give you output like:

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

Rony
  • 196
  • 2
  • 15