tablediff.exe – Compare and Synchronize your SQL Server tables

Need to check if your tables in 2 different servers are out-of-sync? SQL Server comes with a command line tool that does the job. It’s called tablediff.exe (read up BOL entry for this nifty tool).

By default, you can find this in the COM directory of your SQL Server install folder.

In SQL Server 2005 by default it will be in:
C:\Program Files\Microsoft SQL Server\90

In SQL Server 2008 / SQL Server 2008 R2 by default it will be in:
C:\Program Files\Microsoft SQL Server\100

These are the switches you can specify for the tool:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Administrator>cd C:\Program Files\Microsoft SQL Server\100\COM

C:\Program Files\Microsoft SQL Server\100\COM>tablediff.exe /?
Microsoft (R) SQL Server Replication Diff Tool
Copyright (c) 2008 Microsoft Corporation

User-specified agent parameter values:
/?

 Replication Diff Tool Command Line Options

        usage: tablediff

          -- Source Options --
 -sourceserver          Source Host
 -sourcedatabase        Source Database
 -sourceschema          Source Schema Name
 -sourcetable           Source Table or View
 -sourceuser            Source Login
 -sourcepassword        Source Password
 -sourcelocked          Lock the source table/view durring tablediff

          -- Destination Options --
 -destinationserver     Destination Host
 -destinationdatabase   Destination Database
 -destinationschema     Destination Schema Name
 -destinationtable      Destination Table or View
 -destinationuser       Destination Login
 -destinationpassword   Destination Password
 -destinationlocked     Lock the destination table/view durring tablediff

          -- Misc Options --
 -t             Timeout
 -c             Column Level Diff
 -f             Generate Fix SQL (You may also specify a file name and path)
 -q             Quick Row Count
 -et            Specify a table to put the errors into
 -dt            Drop the error table if it exists
 -o             Output file
 -b             Number of bytes to read for blob data types
 -strict        Strict compare of source and destination schema
 -rc            Number of retries
 -ri            Retry interval

Here is an example usage. Note this has to be all in one line at the Command Prompt (I just separated them out into different lines for clarity):
Read the rest of this entry »

VN:F [1.9.22_1171]
Rating: 9.0/10 (7 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Retrieve SSRS Report Definition, Role Assignments, Executions Using T-SQL

Just a few queries against the ReportServer database that might come in handy…
Of course, these are just some sample queries. Tune and modify according to your needs …
Read the rest of this entry »

VN:F [1.9.22_1171]
Rating: 8.9/10 (17 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Executing Batches Multiple Times (SQL Server 2005 only)

In SQL Server 2005, we can execute batches multiple times using the following syntax following the GO delimiter

GO n

– Sample Script

   1: DECLARE @id int
   2:  
   3: SELECT @id = MAX(id)
   4: FROM #tmp 
   5:  
   6: INSERT INTO #tmp
   7: VALUES (@id + 1)
   8:  
   9: SELECT MAX(id)
  10: FROM #tmp
  11:  
  12: GO 5

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
`