Monday, 18 January 2016

Set Identity in Existing table having value already in SQL Server

Suppose that you have a table with AreaID but for that column you forgot set Identity. later you got it. Now you want to set identity without effecting the current records, and you only enabled Identity with seed 1.
Then what would be the next value for AreaID in our below table example
Now change the table definition by setting Identity

Now try to add the record in above table what would be then value of AreaID?
Ans : 112, Sql server will pick then max AreaID exist in table and increment by one, so in our table max AreaID was 111, so our new value 112 after enable Identity 

Visit Our New Site for HR Interview Questions Answers
Sponsored Ads

1 comment:

  1. What a Excellent post. I really found this to much informative. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks! Keep blogging!!