Thursday, January 2, 2014
Tuesday, January 4, 2011
Above tablediff utility is very useful for comparing tables.It is not only tells us which records / columns are different but can also generate a SQL script to update the second table to make it the same as the first table.
You have to navigate to following path the use this utility
SELECT 'C:\Program Files\Microsoft SQL Server\100\COM>
Then type command ;
But only limitation is you could compare one table at a time. Even though you can do some interesting work to overcome this. That is Just go to the SQL sever and type following command execute it. So it will generate the script for all the table. Then you can add it into .bat file.
SELECT 'C:\Program Files\Microsoft SQL Server\100\COM>tablediff -sourceserver "SourceDBName" -sourcedatabase "T1" -sourcetable ' + '"' + name +'" ' + '-destinationserver "DestinationDBName" -destinationdatabase "T2" -destinationtable ' + '"' + name +'" ' + ' -o d:\' + name +'_Script_out.txt'
WHERE xtype = 'U'
Monday, January 3, 2011
To run multiple external scripts do as follows;
Suppose you are having following scripts in a folder. c:\scripts\script1.sql, c:\scripts\script1.sql
If you add the following example to .bat file ,it runs those scripts from the command line and outputs the queries and results to a text file located at C:\Result.txt.
sqlcmd -S ERANGA-PC\SQLEXPRESS -d T1 -U sa -P Qwer1234 -i c:\scripts\script1.sql -i c:\scripts\script1.sql –o c:\scripts\Result.sql
Sometimes we do some recurrent works those can be automated.
Few months back in a integration of two project I had to create multiple database scripts to merge those two. There are more than twenty scripts.Initially I run those one by one and it took long time to create the DB.
We don’t care to automate those recurrent work .Just Do at the point you need. Once you get to know its recurrent you will regret I could have automate this.
By automating recurrent works [Those can automate] you can save your time