SQL Server 2012 – How to Script Data in Deterministic Order

sql serversql-server-2012

When I script data in my database in SSMS Tasks->Generate Scripts and then select data-only it turns out that the insert statements are generated in different order each time when even a smallest change occurs. This makes it impossible for the developers to run a diff program with the previous scripted data and see the data changes: all the tables every time are reshuffled around even if no rows were inserted/deleted so that a diff program can't really show the few data changes in coherent manner.

Is there a way to script data in a database so that they return roughly the same order if no major data additions/deletions that might affect the order happen?

Best Answer

I personally would use a tool (as indeed I already use) , such as are sold by Apex, Red Gate, Toad, and others. These could be used to script only the rows that have changed. That would make your looking for changes very simple indeed.

If you are looking for a free tool you might examine http://opendbiff.codeplex.com/. I have not personally used it, but some people find it useful. (There are doubtless other such tools in the public domain.)