|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Sunday, May 19, 2013 11:16 PM
Points: 1,061,
Visits: 1,151
|
|
Execute this code and you will get duplicate values in Identity values--
CREATE TABLE IdentTest ( Ident INT NOT NULL IDENTITY (1,1) , varfield varchar(100) )
INSERT INTO IdentTest VALUES ('xyz') -- <== Added to original INSERT INTO IdentTest VALUES ('123') -- <== Added to original
SELECT Ident FROM IdentTest -- Result 1,2
DBCC CHECKIDENT ('IdentTest',RESEED,100) --Checking identity information: current identity value '2', current column value '100'.
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest --Result 1,2,101
DBCC CHECKIDENT ('IdentTest',RESEED,100) --Checking identity information: current identity value '101', current column value '100'.
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest --Result 1,2,101,101
Its intresting to know that functionality of identity is exploiting in this way
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 8:24 AM
Points: 1,176,
Visits: 1,253
|
|
kapil_kk (10/22/2012) Execute this code and you will get duplicate values in Identity values--
CREATE TABLE IdentTest ( Ident INT NOT NULL IDENTITY (1,1) , varfield varchar(100) )
INSERT INTO IdentTest VALUES ('xyz') -- <== Added to original INSERT INTO IdentTest VALUES ('123') -- <== Added to original
SELECT Ident FROM IdentTest -- Result 1,2
DBCC CHECKIDENT ('IdentTest',RESEED,100) --Checking identity information: current identity value '2', current column value '100'.
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest --Result 1,2,101
DBCC CHECKIDENT ('IdentTest',RESEED,100) --Checking identity information: current identity value '101', current column value '100'.
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest --Result 1,2,101,101
Its intresting to know that functionality of identity is exploiting in this way
Very true..that's what I was trying to point out
~ Lokesh Vij
Guidelines for quicker answers on T-SQL question Guidelines for answers on Performance questions
Link to my Blog Post --> www.SQLPathy.com
Follow me @Twitter

|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 6:39 AM
Points: 9,376,
Visits: 6,472
|
|
Lokesh Vij (10/22/2012)
kapil_kk (10/22/2012) in this case the max ident value would be 101 as with first insert statement the value of ident was 100 and with another insert statement the ident value would be 101 and max from 101 and 100 is 101 so 101 is the max value.. hope its clear to youActually the question posted by John is little different. Execute the below code: CREATE TABLE IdentTest ( Ident INT NOT NULL IDENTITY (1,1) , varfield varchar(100) )
INSERT INTO IdentTest VALUES ('xyz') -- <== Added to original INSERT INTO IdentTest VALUES ('123') -- <== Added to original
DBCC CHECKIDENT ('IdentTest',RESEED,100)
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest -- <== (done away with max) Now the last select statement (done away with max statement intentionally), returns three values 1,2 and 101 Why value 101?? Why not 100 or 102??
If data is present in the table before DBCC CHECKIDENT, the new identity value is the reseed value + current incremenet. In this case, 100 + 1 = 101.
Anyway, nice question.
How to post forum questions. Need an answer? No, you need a question. What’s the deal with Excel & SSIS?
Member of LinkedIn. My blog at LessThanDot.
 MCSA SQL Server 2012 - MCSE Business Intelligence
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 4:24 AM
Points: 1,161,
Visits: 642
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 1:21 AM
Points: 2,476,
Visits: 2,139
|
|
Good question and thanks for an easy start to the week.
------------------------------- Posting Data Etiquette - Jeff Moden Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
Koen Verbeeck (10/22/2012)
Lokesh Vij (10/22/2012)
kapil_kk (10/22/2012) in this case the max ident value would be 101 as with first insert statement the value of ident was 100 and with another insert statement the ident value would be 101 and max from 101 and 100 is 101 so 101 is the max value.. hope its clear to youActually the question posted by John is little different. Execute the below code: CREATE TABLE IdentTest ( Ident INT NOT NULL IDENTITY (1,1) , varfield varchar(100) )
INSERT INTO IdentTest VALUES ('xyz') -- <== Added to original INSERT INTO IdentTest VALUES ('123') -- <== Added to original
DBCC CHECKIDENT ('IdentTest',RESEED,100)
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest -- <== (done away with max) Now the last select statement (done away with max statement intentionally), returns three values 1,2 and 101 Why value 101?? Why not 100 or 102?? If data is present in the table before DBCC CHECKIDENT, the new identity value is the reseed value + current incremenet. In this case, 100 + 1 = 101. Anyway, nice question. Thank you Koen for the good succinct way to state how this works. It did tickle my urge to keep playing, though... Try predicting the result of the final SELECT in this script:
CREATE TABLE IdentTest ( --Ident INT NOT NULL IDENTITY (1,1) varfield varchar(100) )
INSERT INTO IdentTest VALUES ('xyz') INSERT INTO IdentTest VALUES ('123')
Select * from IdentTest
ALTER TABLE IdentTest Add Ident INT IDENTITY (1,1)
INSERT INTO IdentTest VALUES ('abc')
SELECT Ident FROM IdentTest where varfield = 'abc'
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 3,129,
Visits: 4,312
|
|
Good back-to-basics question, thanks, Kenneth
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 5:11 PM
Points: 7,104,
Visits: 7,168
|
|
Nice easy question.
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Saturday, March 16, 2013 9:53 AM
Points: 847,
Visits: 768
|
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 10:27 AM
Points: 690,
Visits: 1,100
|
|
| Good question, Thanks. Also, enjoy the discussion that followed.
|
|
|
|