Alter a table column with auto increment by 1 in derby

后端 未结 7 1571
囚心锁ツ
囚心锁ツ 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:33

    To alter the column to be auto-generated, the code is

    ALTER TABLE ISSUERECIPT ALTER IRCODE SET INCREMENT BY 1;
    

    BUT the column must already be defined with the IDENTITY attribute (as written in this documentation).

    In most cases (assuming that you too), the primary key column is not set as IDENTITY. Therefore, you may intend to alter the column to IDENTITY, but that is impossible.

    The only way is to drop the table and create it again, as written here.

提交回复
热议问题