Please note that you will have to "set identity insert" to be able to
populate the identity column.
Instead of a new table, you MAY be able to get away with
- rename the old key column
- add the new identify
- set identity insert on
- update the identity column
- set identity insert off
- delete original key column
PLEASE NOTE: I have not actually tried this, but it should work in theory.
"Lyle H. Gray" <gr**@no.spam.cs.umass.edu.invalid> wrote in message
news:Xn**********************************@130.81.6 4.196...
gj*@o2.pl (grzes) wrote in news:e02bcd3.0411170538.5ab97764
@posting.google.com:
MS SQL Server 2000.
My case is: I have the table T with primary key calling __recid int
without identity property. This table includes a lot of records (about
1000000). I need to convert __recid's data type to IDENTITY.
As you know sql sentence: "alter table T alter column __recid int
IDENTITY not null" does not work with not-empty tables.
I use the SQL Enterprise Manager which can convert the field __recid
into identity but I need another way to solve the problem, probably I
should use TSQL. I don't know...
Easiest method is to create a new table with an IDENTITY column and copy
the rows from the old table into it. Then rename the tables appropriately
so that the new table has the old table's name.
Regards,
Lyle