I’m trying to add an autoincrement column to an existing table with no data in it. Is this possible?

0

I’m trying to add an autoincrement column to an existing table with no data in it. Is this possible?

Frank Bell Answered question August 9, 2022
0

Yes. This is easy to do by running the following statement. [Again, this ONLY works if there is NO DATA in the table at all.]

ALTER TABLE EXAMPLE_TABLE ADD COLUMN YOUR_ID INT IDENTITY(1,1);
or
ALTER TABLE EXAMPLE_TABLE ADD COLUMN YOUR_ID INT AUTOINCREMENT(1,1);
or
ALTER TABLE EXAMPLE_TABLE ADD COLUMN YOUR_ID INT AUTOINCREMENT START 1 INCREMENT 1;

*Note: You will notice that the terms/syntax of AUTOINCREMENT is exactly the same as IDENTITY.
Also, if you do not specify a START VALUE or an INCREMENT VALUE then the default values for both of them are equal to 1.

Frank Bell Answered question August 9, 2022
You are viewing 1 out of 1 answers, click here to view all answers.