-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_tablediff_statements.sql
More file actions
51 lines (35 loc) · 1.75 KB
/
Copy pathgenerate_tablediff_statements.sql
File metadata and controls
51 lines (35 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
run this script within the scope of the source database listed
in the @sourcedb local variable below
take the results and save them to a file with a .bat extension
the log files generated will specify the name of the .sql file that
contains the "fixing" sql statement
*/
declare @tbl sysname, @sch sysname, @srcinstance varchar( 255 ), @destinstance varchar( 255 ),
@sourcedb varchar( 255 ), @destdb varchar( 255 ), @sqlstr varchar( 2048 ), @outputfile varchar( 4096 )
select @srcinstance = '' -- source instance
select @destinstance = '' -- instance where changes could/would be applied
select @sourcedb = '' -- database that will be source of data matching
select @destdb = '' -- where data mismatach updates will be applied
-- this script assumes that we're going to do a match up against all
-- tables in the database - if you want to only match up against published
-- article tables we can update the script
declare tableloop cursor for
select a.name, b.name
from sys.schemas a
inner join sys.tables b
on a.schema_id = b.schema_id
and b.type = 'U'
open tableloop
fetch next from tableloop into @sch, @tbl
while ( @@FETCH_STATUS ) != -1
begin
-- plug in location for where files are to be generated
select @outputfile = '' + '\' + @sch + '_' + @tbl + '_output.txt'
select @sqlstr = 'tablediff -f -o ' + @outputfile + ' -sourceserver ' + @srcinstance + ' -sourcedatabase ' + @sourcedb
select @sqlstr = @sqlstr + ' -sourceschema ' + @sch + ' -sourcetable ' + @tbl + ' -destinationserver ' + @destinstance
select @sqlstr = @sqlstr + ' -destinationdatabase ' + @destdb + ' -destinationschema ' + @sch + ' -destinationtable ' + @tbl
print @sqlstr
fetch next from tableloop into @sch, @tbl
end
deallocate tableloop