Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

MS Sql Convert int column to identity conserving data

I have a field with integers, they are not repeated and go from 1 to 1000, I need it to set it as an identity column (1,1) preserving the data it has since it is the key for a relation with another table.

This table was imported from a system that incremented this field by 1 manually.


0
robrodp
Asked:
robrodp
1 Solution
 
zapacila89Commented:
If you have access to enterprise manager or SSMS, you can browse to the table, right click => design.

In the definition of the table, select the column, set identity on and seed value to the last existing value in the table. Do save.

More info on the steps

Highlight the column (actually a row in this presentation) you are interested in by left clicking the gray square to the left of the column name.
With the row highlighted the column detail will be shown in the bottom half of the window with all the things you need.

Next record inserted into to the table will have the next identity column auto incremented.

(In SSMS 2005 you simple change the column to be as identity same from the design window (rigt-clik on table name an click design) and clicking on the column in the bottom will appear a table of properties which contains Identity specification. In SSMS 2005 it will automatically pick from the next number)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now