| Author |
Topic |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-01-21 : 11:21:28
|
when i use :set identity_insert mytable on and i then turn it off will the autoincremnet will continue from the last most high ID?thnaks in advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-01-21 : 12:08:04
|
| It will continue from the current seed.If the last value inserted is greater than the seed then the seed will be set to the new value.You can check (and set) the seed via dbcc checkident.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-01-21 : 12:11:50
|
| thnaks alotIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-01-22 : 04:22:14
|
1 more question : if i do :DBCC CHECKIDENT ('table1', RESEED, 30)and i have in the tables id's from 35 to 40and i start to do insert will it override the existing ones or skip them?thnaks in advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-22 : 04:29:34
|
| [code]create table #seed (i int identity(1, 1), data varchar(10))insert #seed (data)select 'peso'select * from #seedset identity_insert #seed oninsert #seed (i, data)select 10, 'peleg2k'select * from #seedset identity_insert #seed offinsert #seed (data)select 'sqlteam'select * from #seedDBCC CHECKIDENT ('#seed', RESEED, 9)insert #seed (data)select 'test'select * from #seeddrop table #seed[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-22 : 04:32:11
|
And now try thiscreate table #seed (i int identity(1, 1) primary key, data varchar(10))insert #seed (data)select 'peso'select * from #seedset identity_insert #seed oninsert #seed (i, data)select 10, 'peleg2k'select * from #seedset identity_insert #seed offinsert #seed (data)select 'sqlteam'select * from #seedDBCC CHECKIDENT ('#seed', RESEED, 9)insert #seed (data)select 'test'select * from #seeddrop table #seedPeter LarssonHelsingborg, Sweden |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-01-22 : 10:53:44
|
| >> It will continue from the current seed.It updates the seed on insert and takes the next value for the next identity.It doesn't look to see what is in the table.Identities aren't guaranteed to be unique or consecutive.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-01-23 : 01:52:53
|
quote: Identities aren't guaranteed to be unique or consecutive.
what do u mean by that? that i can recive a duplicate id????Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-23 : 01:54:52
|
quote: Originally posted by pelegk2 what do u mean by that? that i can recive a duplicate id????
If you even bothered to run the script I posted, you would have noticed that by now...Peter LarssonHelsingborg, Sweden |
 |
|
|
|