Another uneasy task to be accomplished in MS SQL Server is to compare and find out what are the additional columns exist in between a same table but in 2 different version of database.
First, need to extract all the columns in the table from the 2 databases.
publicSqlDataReader GetAllColumns(string strSchema, string strTable)
string strSQL = “SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_SCHEMA = ‘” + strSchema + “‘ AND TABLE_NAME= ‘[“ +strTable + “]'”;
SqlCommand cmd = newSqlCommand(strSQL, connCol);
drdCol = cmd.ExecuteReader();
Put them in 2 Lists.
After that compare them and put them in files.
staticList<string> Diff(List<string> ar, List<string> ar1)
List<string> arTemp = newList<string>();
foreach (string cols in ar)
blnFound = false;
foreach (string cols1 in ar1)
blnFound = true;
if (blnFound == false)
The code can also be downloaded at http://code.msdn.microsoft.com/sqlutilities