Alter a table column with auto increment by 1 in derby

后端 未结 7 1529
囚心锁ツ
囚心锁ツ 2021-01-11 18:21

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

相关标签:
7条回答
  • 2021-01-11 18:56

    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

    0 讨论(0)
提交回复
热议问题