比較2個資料庫的表不同以及表結構不同

來源:互聯網
上載者:User
用來顯示2個資料庫中具有不同表名的表的資訊以及具有相同表的表結構不同的資訊。
 /*Test1Test3DataBase2 Test3*/with A as(select name,type from Test1.sys.objects where type in ('U','V')),B as(select name,type from Test3.sys.objects where type in ('U','V'))select case when A.type is null then B.type else A.type end as Kind, A.name as Test1,B.name as Test3  from  A full outer join  Bon A.name=b.name and A.type=B.typewhere A.name is null or B.name is nullgowith A as(select name,type from Test1.sys.objects where type in ('U','V')),B as(select name,type from Test3.sys.objects where type in ('U','V')) ,AWithB as(select case when A.type is null then B.type else A.type end as type, A.name as TableName  from  A inner join  Bon A.name=b.name and A.type=B.type),---- AC as( select obj.name as TableName,obj.type,col.name from test1.sys.objects obj inner join test1.sys.columns col on obj.object_id =col.object_idwhere obj.type in ('U','V')),BC as(select obj.name as TableName ,obj.type,col.name from Test3.sys.objects obj inner join Test3.sys.columns col on obj.object_id =col.object_idwhere obj.type in ('U','V')),ACWithBC as(select case when Ac.type is null then BC.type else AC.type end as Type,case when Ac.TableName is null then BC.TableName else AC.TableName end as TableName, AC.name as Test1  ,BC.name as Test3from  AC full outer join  BCon AC.name=bC.name and AC.type=BC.type and AC.TableName =BC.TableName where AC.name is null or BC.name is null)select AWithB.TableName ,AWithB.type ,ACWithBC.Test1 ,ACWithBC .Test3  from AWithB left join ACWithBC on AWithB.type=ACWithBC .Type and AWithB.TableName =ACWithBC.TableNamego 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.