I apoligize if you already know this and I seem to be “beating a dead horse”. I’m just concerned you may not understand the function of an identity column. I’m trying to demonstrate that here. The code below can be plugged in and run ASIS.
I may be all wet as far as your application goes but I've worked in a number of commercial IT shops where we rely on identity columns to build our foriegn keys. You have several entries in this post trying to get around it and it makes me nervous :-)Code:-- create table with identity column CREATE TABLE #VBForums( Id INT IDENTITY(1,1) PRIMARY KEY NOT NULL, Something VARCHAR(15) NOT NULL ) -- don't allow identity inserts set IDENTITY_INSERT #VBForums off Insert into #VBForums(Something) values('SomeThing - 1') Insert into #VBForums(Something) values('SomeThing - 2') Insert into #VBForums(Something) values('SomeThing - 3') -- Notice the ID is incremented automatically select * from #VBForums /* ID SomeThing 1 SomeThing - 1 2 SomeThing - 2 3 SomeThing - 3 */ -- In many applications the ID value generated is used as a foriegn key to other tables -- The next insert would create normally an ID value of "4" -- You seem to what to circumvent that -- Allow identity inserts set IDENTITY_INSERT #VBForums on Insert into #VBForums(id,Something) values(7,'SomeThing - 4') -- That "broke" the numbering that would have occured. Instead of "4"it is "7" select * from #VBForums /* ID SomeThinf 1 SomeThing - 1 2 SomeThing - 2 3 SomeThing - 3 7 SomeThing - 4 */ drop table #VBForums
I'm thinking it is there for a reason. I'll get off my soapbox now :-)




Reply With Quote