How to add an identity column to an existing table


Let’s say your existing table is Test and it has two columns (X and Y).
You need a third column which will be an identity column and it will be named as ID

 

CREATE TABLE Test1 like Test;

ALTER TABLE Test1 add column ID integer not null;

ALTER TABLE Test1 alter column ID set generated always as identity;

INSERT INTO Test1 (X,Y) SELECT X,Y FROM Test;

Comments

Popular posts from this blog

Db2 export command example using file format (del , ixf)

Difference between DB2 Terminate and Connect Reset

Database recovery methods