sql - ROW_NUMBER vs IDENTITY and ORDER BY -


is there difference (in terms of result set, performance or semantic meaning) between using row_number , using identity order statement in ms sql server? instance, given table column "firstname" there difference between

select firstname, row_number() on (order firstname) position #mytemptable mytable 

and

select firstname, identity(bigint) position #mytemptable mytable order firstname 

the semantic meaning different. first example creates integer column sequential value.

the second example, using identity() creates identity column. means subsequent inserts increment.

for instance, run code:

select 'a' x, identity(int, 1, 1) id #t;  insert #t(x) values('b');  select * #t; 

as processing, 2 should same in case, because firstname needs sorted. if rows wider, wouldn't surprised if row_number() version edged out other in performance. row_number() 1 column sorted , mapped original data. identity() entire row needs sorted. difference in performance informed speculation.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -