比較2個資料庫的差異

2022-01-11 21:17:50 字數 1586 閱讀 4317

對已經執行的系統進行大規模模組開發之後,對資料庫和程式修改比較大。

如果開始開發的時候沒有嚴格要求,或者人員沒有按照要求做,或者人員離職交接不合格,很容易造成文件不完整,必須比較兩個資料庫的差別。

下面的sql比較出兩個資料庫中表結構有差的地方。

select  obj.name as tablename, col.name as

colname, col.xtype,

col.length

into

#tmp1

from eshipping_new_qa_user_1_backup.dbo.syscolumns col inner

join

eshipping_new_qa_user_1_backup.dbo.sysobjects obj

on col.id =

obj.id

order

byobj.name

select obj.name as tablename, col.name as

colname, col.xtype,

col.length

into

#tmp2

from eshipping_20140805.dbo.syscolumns col inner

join

eshipping_20140805.dbo.sysobjects obj

on col.id =

obj.id

order

byobj.name

select tablename,colname,0

as xtypeold,0

as lengthold,0

as xtypenew,0

aslengthnew

into

#t***

from (select tablename,colname from #tmp1 union

select tablename,colname from

#tmp2)

bupdate #t*** set xtypeold=#tmp1.xtype,lengthold=#tmp1.length from #tmp1 where #t***.tablename=#tmp1.tablename and

#t***.colname

=#tmp1.colname

update #t*** set xtypenew=#tmp2.xtype,lengthnew=#tmp2.length from #tmp2 where #t***.tablename=#tmp2.tablename and

#t***.colname

=#tmp2.colname

select

*from

#t***

where xtypeold<>xtypenew or lengthold<>

lengthnew

drop

table

#tmp1

drop

table

#tmp2

drop

table #t***

view code

比較兩個資料庫的表結構差異

比較兩個資料庫的表結構差異 鄒建 2003.9 引用請保留此資訊 呼叫示例 exec p comparestructure xzkh model xzkh new if exists select from dbo.sysobjects where id object id n dbo p comp...

比較兩個資料庫的表結構差異

比較兩個資料庫的表結構差異 鄒建 2003.9 引用請保留此資訊 呼叫示例 exec p comparestructure xzkh model xzkh new if exists select from dbo.sysobjects where id object id n dbo p comp...

比較兩個資料庫的表結構差異

比較兩個資料庫的表結構差異 鄒建 2003.9 引用請保留此資訊 呼叫示例 exec p comparestructure xzkh model xzkh new if exists select from dbo.sysobjects where id object id n dbo p comp...