Alter a table column with auto increment by 1 in d

2020-03-12 03:28发布

I have created a table in derby Netbeans and now i realize that i need to make a column as auto incremented by 1 which is a primary key. How can i do so? I tried the following code but was in vain.

ALTER TABLE ISSUERECIPT ALTER IRCODE SET INCREMENT BY 1;

Do i need to create the table once again or can it be possible some other way?

7条回答
再贱就再见
2楼-- · 2020-03-12 03:57

Check this

ALTER TABLE ISSUERECIPT 
ALTER IRCODE INTEGER NOT NULL 
GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1);

If your table is empty, Try this

ALTER TABLE DROP  PRIMARY KEY your_primaryKeyContrainName ; 
ALTER TABLE ISSUERECIPT DROP COLUMN IRCODE ;
ALTER TABLE ISSUERECIPT ADD COLUMN 
IRCODE PRIMARY KEY INTEGER NOT NULL 
GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1);

See Also : Derby ALTER TABLE Syntax

查看更多
登录 后发表回答