• Reginald J Ray Jr (3/7/2008)


    This didn't work for me initially. It duplicated a column four times. I had to modify the code as below:

    Original line:

    WHERE O1.Name = @Target_Table) AS C1

    New line:

    WHERE O1.Name = @Target_Table and T1.Name <> 'sysname') AS C1

    Original line:

    WHERE O2.Name = @Source_Table) AS C2

    New line:

    WHERE O2.Name = @Source_Table and T2.Name <> 'sysname') AS C2

    With those changes it worked. Will be a time-saver. 'Message' was the column name that was duplicated.

    Thanks

    Yes, SQL Server will make multiple entries in SysColumns for some columns, causing the duplicate lines in the generated script. I put your fix in place, along with a "DISTINCT" clause on the subqueries. Thanks for your response!