title: How can I sort the output of a generated SQL script?
body: <p>I'm comparing two SQL server databases (development and live environment, SQL2005 and SQL2008 respectively) to check for differences between the two. If I generate a script for each database I can use a simple text comparison to highlight the differences.</p>
  
  <p>Problem is the scripts need to be in the same order to ease comparison and avoid simple differences where the order of the stored procedures is different, but their contents are the same.</p>
  
  <p>So if I generate this from development:</p>
  
  <pre><code>1: CREATE TABLE dbo.Table1 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  2: CREATE TABLE dbo.Table2 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  3: CREATE TABLE dbo.Table3 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  </code></pre>
  
  <p>And this from live:</p>
  
  <pre><code>1: CREATE TABLE dbo.Table1 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  2: CREATE TABLE dbo.Table3 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  3: CREATE TABLE dbo.Table2 (ID INT NOT NULL, Name VARCHAR(100) NULL)
  </code></pre>
  
  <p>Comparing the two highlights lines 2 and 3 as different, but they're actually identical, just the generate script wizard did table3 before table 2 on the live environment. Add in 100's of tables, stored procedures, views, etc. and this quickly becomes a mess.</p>
  
  <p>My current options are:</p>
  
  <ol>
  <li>Manually sort the contents before comparison</li>
  <li>Create a program to create the scripts in a specific order</li>
  <li>Find a freeware application that sorts the generated scripts</li>
  <li>Pay for a product that does this as part of its suite of tools</li>
  <li>(Some other way of doing this)</li>
  </ol>
  
  <p>Hopefully, I'm only missing the checkbox that says "Sort scripts by name", but I can't see anything that does this. I don't feel I should have to pay for something as simple as a 'sort output' option or lots of other unneeded tools, so option 4 should just be a last resort.</p>
  
  <p><em>EDIT</em>
  I have full access to both environments, but the live environment is locked down and hosted on virtual servers, with remote desktoping the typical way to access live.  My preference is to copy what I can to development and compare there.  I can generate scripts for each type of object in the database as separate files (tables, SP's, functions, etc.)</p>