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.
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.
So if I generate this from development:
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)
And this from live:
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)
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.
My current options are:
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.
EDIT 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.)
The ORDER BY command is used to sort the result set in ascending or descending order. The ORDER BY command sorts the result set in ascending order by default. To sort the records in descending order, use the DESC keyword.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
By default SQL ORDER BY sort, the column in ascending order but when the descending order is needed ORDER BY DESC can be used. In case when we need a custom sort then we need to use a CASE statement where we have to mention the priorities to get the column sorted.
The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns.
Depending on your version of Visual Studio 2010 (if you have it), you can do this easily via the data menu, based on your original intent, you might save yourself some time.
Edit: Generating the actual DB's and then comparing the schema comparison tool as shown below is the same net effect as comparing two script files and you don't have to worry about line breaks etc.
Red_gate's SQLCompare is the best thing to use for this, worth every penny.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With