Lets demonstrate it with the help of a temporary table, here we are creating a table with identity column and set the seed value to 1 and increment factor to 1
create table #tempReseed
(id int identity(1,1),
col1 varchar(10));
Command(s) completed
successfully.
Now before we execute any insert statement on the table
we are Reseed the Identity value to 15
dbcc
CHECKIDENT('#tempReseed',reseed,15)
Checking identity
information: current identity value 'NULL'.
DBCC execution completed.
Now lets insert a records and check what value will get
inserted to id column.
insert into #tempReseed(col1) values('ABC')
(1 row(s) affected)
Querying the table after insertion.
select * from #tempReseed
id col1
----------- ----------
15 ABC
Here we found the id is set with reseed value i.e. 15
Lets again reseed the identity value, this time to 25
dbcc
CHECKIDENT('#tempReseed',reseed,25)
Checking identity
information: current identity value '15'.
DBCC execution completed.
Lets fire an insertion after reseeding identity value
to 25
insert into #tempReseed(col1) values('DEF')
(1 row(s) affected)
Lets query the table to find what gets inserted this
time.
select * from
#tempReseed
id col1
----------- ----------
15 ABC
26 DEF
Cool!!! This time Reseed value was added with the
incremented factor i.e. 1 an new value formed was 25+1 =26 which gets inserted.
Conclusion: First insertion will always takes the seed
value, all other insertion following first will take seed/reseed value and add
increment factor to form the identity value.
Code and enjoy … very sync :)
No comments:
Post a Comment