码迷,mamicode.com
首页 > 数据库 > 详细

比较2个数据库的差异

时间:2014-08-07 21:52:40      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   数据   2014   

对已经运行的系统进行大规模模块开发之后,对数据库和程序修改比较大。

如果开始开发的时候没有严格要求,或者人员没有按照要求做,或者人员离职交接不合格,很容易造成文档不完整,必须比较两个数据库的差别。

下面的SQL比较出两个数据库中表结构有差的地方。

 
 
bubuko.com,布布扣
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 BY obj.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 BY obj.name

select  tablename,colname,0 as xtypeold,0 as lengthold,0 as xtypenew,0 as lengthnew
into #tmp3
from (select tablename,colname from #tmp1 union select tablename,colname from #tmp2)
b

update #tmp3 set xtypeold=#tmp1.xtype,lengthold=#tmp1.length  from #tmp1 where #tmp3.tablename=#tmp1.tablename and
#tmp3.colname=#tmp1.colname

update #tmp3 set xtypenew=#tmp2.xtype,lengthnew=#tmp2.length  from #tmp2 where #tmp3.tablename=#tmp2.tablename and
#tmp3.colname=#tmp2.colname

select * from #tmp3
where xtypeold<>xtypenew or lengthold<>lengthnew 

drop table #tmp1
drop table #tmp2
drop table #tmp3
View Code

 


 

比较2个数据库的差异,布布扣,bubuko.com

比较2个数据库的差异

标签:style   blog   http   color   os   io   数据   2014   

原文地址:http://www.cnblogs.com/wonder223/p/3897905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!