1

I have created a table in oracle database which I named USERS and I have created a column USER_ID with type NUMBER which i set as primary key.

How can I modify the column USER_ID to make it auto increment by 1 ?

Any help please ?

1

If you insist on using IDENTITY, it is not be possible - you cannot modify non-identity column to identity. However, Oracle lets you use sequence.nextval as default, so you may get similar functionality :

CREATE SEQUENCE SEQ_USER START WITH 1000; --assuming max(USERS.user_id) =999
ALTER TABLE USERS MODIFY (USER_ID DEFAULT SEQ_USER.NEXTVAL); 

It will work as GENERATED BY DEFAULT AS IDENTITY.

| improve this answer | |
1

That is not possible.

ALTER TABLE

identity_clause

Use identity_clause to modify the properties of an identity column. You cannot specify this clause on a column that is not an identity column.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.