首页 > 代码库 > 比较2个数据库的差异
比较2个数据库的差异
对已经运行的系统进行大规模模块开发之后,对数据库和程序修改比较大。
如果开始开发的时候没有严格要求,或者人员没有按照要求做,或者人员离职交接不合格,很容易造成文档不完整,必须比较两个数据库的差别。
下面的SQL比较出两个数据库中表结构有差的地方。
SELECT obj.name AS TableName, col.name AS ColName, col.xtype, col.lengthinto #tmp1FROM eShipping_New_QA_User_1_BackUp.dbo.syscolumns col INNER JOIN eShipping_New_QA_User_1_BackUp.dbo.sysobjects obj ON col.id = obj.idORDER BY obj.nameSELECT obj.name AS TableName, col.name AS ColName, col.xtype, col.lengthinto #tmp2FROM eShipping_20140805.dbo.syscolumns col INNER JOIN eShipping_20140805.dbo.sysobjects obj ON col.id = obj.idORDER BY obj.nameselect tablename,colname,0 as xtypeold,0 as lengthold,0 as xtypenew,0 as lengthnewinto #tmp3from (select tablename,colname from #tmp1 union select tablename,colname from #tmp2)bupdate #tmp3 set xtypeold=#tmp1.xtype,lengthold=#tmp1.length from #tmp1 where #tmp3.tablename=#tmp1.tablename and#tmp3.colname=#tmp1.colnameupdate #tmp3 set xtypenew=#tmp2.xtype,lengthnew=#tmp2.length from #tmp2 where #tmp3.tablename=#tmp2.tablename and#tmp3.colname=#tmp2.colnameselect * from #tmp3where xtypeold<>xtypenew or lengthold<>lengthnew drop table #tmp1drop table #tmp2drop table #tmp3
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。