compare the table and cdc table columns
select schema_name(schema_id)+'.'+name [Tablename],a.Col from (
SELECT object_id, STUFF((SELECT ',' + cc.[name]
FROM sys.columns cc
WHERE cc.object_id=c.object_id
ORDER BY object_id
FOR XML PATH('')), 1, 1, '') AS Col
FROM sys.columns c
where c.object_id=1481264532
GROUP BY c.object_id)
a join sys.tables t on a.object_id=t.object_id
where t.is_tracked_by_cdc=1
order by name desc
select replace(replace(name,'_CT',''),'_','.') as [TableName],a.Col from (
SELECT object_id, STUFF((SELECT ',' + cc.[name]
FROM sys.columns cc
WHERE cc.object_id=c.object_id
and
cc.name not in ('__$start_lsn',
'__$end_lsn',
'__$seqval',
'__$operation',
'__$update_mask','__$command_id')
ORDER BY object_id
FOR XML PATH('')), 1, 1, '') AS Col
FROM sys.columns c
where c.object_id= 524841232
GROUP BY c.object_id) a join sys.tables t on a.object_id=t.object_id
where t.is_ms_shipped=1 order by name desc
select * from #t1 a left join
#t2 b on a.tablename=b.tablename
where a.Col<>b.Col
============ alternate approach =====
select
* from (select c.TABLE_SCHEMA+'.'+c.TABLE_NAME as [table], c.column_name
from information_schema.columns c
join sys.tables t on c.TABLE_NAME=t.NAME
where t.name not like '%_CT'
and t.is_tracked_by_cdc=1
and c.TABLE_SCHEMA<>'pcm'
and table_name = 'GerritVersionControlSystems' and table_schema = 'dbo'
)c1
full outer join
(
select c.TABLE_SCHEMA+'.'+c.TABLE_NAME as [table], c.column_name
from information_schema.columns c
join sys.tables t on c.TABLE_NAME=t.NAME
where t.name like '%CT'
--and table_name = 'dbo_GerritVersionControlSystems_CT' and table_schema = 'cdc'
and is_ms_shipped=1
and c.column_name not in ('__$start_lsn',
'__$end_lsn',
'__$seqval',
'__$operation',
'__$update_mask','__$command_id'))c2 on c1.column_name = c2.column_name
where c2.column_name is null
-- or c1.column_name is null
and c1.[table]='dbo.GerritVersionControlSystems'
SELECT object_id, STUFF((SELECT ',' + cc.[name]
FROM sys.columns cc
WHERE cc.object_id=c.object_id
ORDER BY object_id
FOR XML PATH('')), 1, 1, '') AS Col
FROM sys.columns c
where c.object_id=1481264532
GROUP BY c.object_id)
a join sys.tables t on a.object_id=t.object_id
where t.is_tracked_by_cdc=1
order by name desc
select replace(replace(name,'_CT',''),'_','.') as [TableName],a.Col from (
SELECT object_id, STUFF((SELECT ',' + cc.[name]
FROM sys.columns cc
WHERE cc.object_id=c.object_id
and
cc.name not in ('__$start_lsn',
'__$end_lsn',
'__$seqval',
'__$operation',
'__$update_mask','__$command_id')
ORDER BY object_id
FOR XML PATH('')), 1, 1, '') AS Col
FROM sys.columns c
where c.object_id= 524841232
GROUP BY c.object_id) a join sys.tables t on a.object_id=t.object_id
where t.is_ms_shipped=1 order by name desc
select * from #t1 a left join
#t2 b on a.tablename=b.tablename
where a.Col<>b.Col
============ alternate approach =====
select
* from (select c.TABLE_SCHEMA+'.'+c.TABLE_NAME as [table], c.column_name
from information_schema.columns c
join sys.tables t on c.TABLE_NAME=t.NAME
where t.name not like '%_CT'
and t.is_tracked_by_cdc=1
and c.TABLE_SCHEMA<>'pcm'
and table_name = 'GerritVersionControlSystems' and table_schema = 'dbo'
)c1
full outer join
(
select c.TABLE_SCHEMA+'.'+c.TABLE_NAME as [table], c.column_name
from information_schema.columns c
join sys.tables t on c.TABLE_NAME=t.NAME
where t.name like '%CT'
--and table_name = 'dbo_GerritVersionControlSystems_CT' and table_schema = 'cdc'
and is_ms_shipped=1
and c.column_name not in ('__$start_lsn',
'__$end_lsn',
'__$seqval',
'__$operation',
'__$update_mask','__$command_id'))c2 on c1.column_name = c2.column_name
where c2.column_name is null
-- or c1.column_name is null
and c1.[table]='dbo.GerritVersionControlSystems'
Comments
Post a Comment