首页 > 数据库技术 > 详细

比较2个数据库的差异

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

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

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

下面的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个数据库的差异

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!