Comparando as estruturas de todas as tabelas de dois bancos de dados diferentes no SQL Server
[sql] use Banco1 SELECT CONCAT(t.name, ‘.’, c.name, ‘ (‘, tp.name, ‘, ‘, c.length, ‘, ‘, c.isnullable, ‘)’) TabelaCampoTipoTamanhoNull, t.name Tabela, c.name Campo, tp.name Tipo, c.length Tamanho, c.isnullable PerniteNullinto #EstruturaA FROM SYSCOLUMNS c inner join SYSOBJECTS t on t.id = c.id inner join SYSTYPES tp on tp.xtype = c.xtype where t.xtype = ‘U’ go use Banco2 SELECT CONCAT(t.name, ‘.’, c.name, ‘ (‘, tp.name, ‘, ‘, c.length, ‘, ‘, c.isnullable, ‘)’) TabelaCampoTipoTamanhoNull, t.name Tabela, c.name Campo, tp.name Tipo, c.length Tamanho, c.isnullable PerniteNull into #EstruturaB FROM SYSCOLUMNS c inner join SYSOBJECTS t on t.id = c.id inner join SYSTYPES tp on tp.xtype = c.xtype where t.xtype = ‘U’ go — Lista as Tabelas e Campos que só existem no A, e logicamente não existem no B SELECT TabelaCampoTipoTamanhoNull ExisteSomenteNoBancoB, Tabela, Campo, Tipo, Tamanho, PerniteNull FROM #EstruturaB where TabelaCampoTipoTamanhoNull not in (SELECT TabelaCampoTipoTamanhoNull FROM #EstruturaA) — Lista as Tabelas e Campos que só existem no B, e logicamente não existem no A SELECT TabelaCampoTipoTamanhoNull ExisteSomenteNoBancoA, Tabela, Campo, Tipo, Tamanho, PerniteNull FROM #EstruturaA where TabelaCampoTipoTamanhoNull not in (SELECT TabelaCampoTipoTamanhoNull FROM #EstruturaB) drop table #EstruturaA; drop table #EstruturaB; [/sql]