Domanda

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
È stato utile?

Soluzione

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)

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top