this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Tuesday, December 23, 2008

Can't ALTER COLUMN to IDENTITY

If you ever try to alter existing primary column with integer datatype to identity from sql script you will get error.

Because you cant alter column whose value is filled prior.

you have options like

1) Create new table with same name and now set that column as identity

2) drop old table

But visual studio gives you abilty to do it in design time. In design just modify table structure and set identity to yes.

Internally visual management studio drop your old table and create new table with same name and structure now will copy old data to this new table.

Keep in mind you can't set Identity by altering existing column.

No comments: