title: Do Inserted Records Always Receive Contiguous Identity Values
body: <p>Consider the following SQL:</p>
  
  <pre><code>CREATE TABLE Foo
  (
      ID int IDENTITY(1,1),
      Data nvarchar(max)
  )
  
  INSERT INTO Foo (Data)
  SELECT TOP 1000 Data
  FROM SomeOtherTable
  WHERE SomeColumn = @SomeParameter
  
  DECLARE @LastID int
  SET @LastID = SCOPE_IDENTITY()
  </code></pre>
  
  <p>I would like to know if I can depend on the 1000 rows that I inserted into table Foo having contiguous identity values. In order words, if this SQL block produces a @LastID of 2000, can I know for certain that the ID of the first record I inserted was 1001? I am mainly curious about multiple statements inserting records into table Foo concurrently. </p>
  
  <p>I know that I could add a serializable transaction around my insert statement to ensure the behavior that I want, but do I really need to? I'm worried that introducing a serializable transaction will degrade performance, but if SQL Server won't allow other statements to insert into table Foo while this statement is running, then I don't have to worry about it.</p>