0

In the following T-SQL script:

CREATE TABLE #testdata 
    (id int IDENTITY(1,1) PRIMARY KEY,
     field VARCHAR(MAX))

INSERT INTO #testdata
VALUES
('this should be row 1'),
('this should be row 2'),
('this should be row 3')

is there any guarantee that id will match the intended row number? This seems to be the case in all my tests so far, but I can't find any documentation saying that this is always the case.

I'd like to rely on this behavior, but I need to be sure that there isn't any factor that might result in a different insert order.

I am using SQL Server 2012.

matko
  • 134
  • 6
  • 1
    Since tables have no inherent user-observable ordering guarantees, the most you can seek is a guarantee about the assignment of `IDENTITY` values to rows, which is what the question I've linked to addresses. – Damien_The_Unbeliever Jan 04 '16 at 08:24
  • The `identity` ill guarantee each insertion ill receive a sequential number. Later you can fetch the rows ordered by that number. – jean Jan 04 '16 at 09:39

0 Answers0