Different result on SQL Server 2008 and SQL Server 2012 -


when executed on sql server 2008, result comes expected in random order. when executed on sql server 2012, result comes in same order present in main table asc.

can't figure out lacking. here's query running in sql server 2008 , sql server 2012.

insert categoryimage1(imageid, categoryid, thumbnail, imagename, gridviewimage, createdon, modifiedon, coordinates, activeflag)    select        imageid, categoryid, thumbnail, imagename,        gridviewimage, createdon, modifiedon, coordinates, activeflag            categoryimage     order        newid() 

your select statement executed return rows. query optimizer determines efficient way return rows based upon available indexes, column statistics, etc. may therefore in table order, or order. order nondeterministic, , may depend on many factors, including available memory, disk io etc. etc.

the results ordered newid(). scalar function executed against each row in order have been returned. please correct me if incorrect here, net effect of 0 (other wasted cpu cycles).

these results inserted target table.

so, summarise, reason sql server 2012 inserting them in different order is choosing different execution planto sql server 2008. may due changes in way optimizer weights plans in 2012, or difference in shape of data, 'freshness' or column / index statistics, available resources, server architecture, etc. etc.

if want insert columns in deterministic order, make sure order clause orders 1 or more unique columns in source data.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -