判断两个数据库中不一样的表和存储过程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断两个数据库中不一样的表和存储过程相关的知识,希望对你有一定的参考价值。

---两表结构不一样
SELECT a.a1,a.a2,a.a3,a.length from
(SELECT a.a1,a.a2,a.a3,a.length, b.a1 AS b1,b.a2 AS b2,b.a3 AS b3,b.length AS b4  from
(select o.name AS a1, c.name AS a2,t.name AS a3,c.length from dbf.sys.syscolumns c
inner join dbf.sys.systypes t on c.xtype= t.xtype
inner join dbf.sys.sysobjects o on c.id= o.id
where   o.xtype=‘u‘
)AS a
LEFT JOIN
(select o.name AS a1, c.name AS a2,t.name AS a3,c.length from hisdb.sys.syscolumns c
inner join hisdb.sys.systypes t on c.xtype= t.xtype
inner join hisdb.sys.sysobjects o on c.id= o.id
where   o.xtype=‘u‘
)AS b
ON a.a1 = b.a1 AND a.a2 = b.a2
)AS a
WHERE a.b1 IS NULL GROUP by a.a1,a.a2,a.a3,a.length

----两个数据库所缺表
SELECT a.a1 from
(SELECT a.a1,a.a2,a.a3,a.length, b.a1 AS b1,b.a2 AS b2,b.a3 AS b3,b.length AS b4  from
(select o.name AS a1, c.name AS a2,t.name AS a3,c.length from dbf.sys.syscolumns c
inner join dbf.sys.systypes t on c.xtype= t.xtype
inner join dbf.sys.sysobjects o on c.id= o.id
where   o.xtype=‘u‘
)AS a
LEFT JOIN
(select o.name AS a1, c.name AS a2,t.name AS a3,c.length from hisdb.sys.syscolumns c
inner join hisdb.sys.systypes t on c.xtype= t.xtype
inner join hisdb.sys.sysobjects o on c.id= o.id
where   o.xtype=‘u‘
)AS b
ON a.a1 = b.a1
)AS a
WHERE a.b1 IS NULL GROUP BY a.a1

---两个数据库所缺存储过程
SELECT a.name,a.b1 from
(
SELECT a.name,b.name AS b1 from
(SELECT a.name FROM dbf.sys.sysobjects AS a WHERE xtype = ‘P‘)AS a
LEFT join
(SELECT a.name FROM hisdb.sys.sysobjects AS a WHERE xtype = ‘P‘)AS b
ON a.name = b.name
)AS a WHERE a.b1 IS null

本文出自 “一切有为法,如梦幻泡影” 博客,请务必保留此出处http://kaixinbuliao.blog.51cto.com/2567365/1745015

以上是关于判断两个数据库中不一样的表和存储过程的主要内容,如果未能解决你的问题,请参考以下文章

一次性删除数据库所有表和所有存储过程 SQL语句

Sql Server 中 根据具体的值 查找该值所在的表和字段

表和存储过程未包含在生成的脚本中

表中的存储过程列表

类与对象

为什么要将表和索引建立在不同的表空间?