时间:2021-07-01 10:21:17 帮助过:32人阅读
CREATE PROC P_COMPDB@DB1 SYSNAME, --第一个库@DB2 SYSNAME --第二个库ASEXEC(SELECT 类型=CASE ISNULL(A.XTYPE,B.XTYPE) WHEN V THEN 视图 ELSE 存储过程 END ,匹配情况=CASE WHEN A.NAME IS NULL THEN 库 [+@DB1+] 中无 WHEN B.NAME IS NULL THEN 库 [+@D
CREATE PROC P_COMPDB @DB1 SYSNAME, --第一个库 @DB2 SYSNAME --第二个库 AS EXEC(' SELECT 类型=CASE ISNULL(A.XTYPE,B.XTYPE) WHEN ''V'' THEN ''视图'' ELSE ''存储过程'' END ,匹配情况=CASE WHEN A.NAME IS NULL THEN ''库 ['+@DB1+'] 中无'' WHEN B.NAME IS NULL THEN ''库 ['+@DB2+'] 中无'' ELSE ''结构不同'' END ,对象名称=ISNULL(A.NAME,B.NAME) FROM( SELECT A.NAME,A.XTYPE,B.COLID,B.TEXT FROM ['+@DB1+']..SYSOBJECTS A,['+@DB1+']..SYSCOMMENTS B WHERE A.ID=B.ID AND A.XTYPE IN(''V'',''P'') AND A.STATUS>=0 )A FULL JOIN( SELECT A.NAME,A.XTYPE,B.COLID,B.TEXT FROM ['+@DB2+']..SYSOBJECTS A,['+@DB2+']..SYSCOMMENTS B WHERE A.ID=B.ID AND A.XTYPE IN(''V'',''P'') AND A.STATUS>=0 )B ON A.NAME=B.NAME AND A.XTYPE=B.XTYPE AND A.COLID=B.COLID WHERE A.NAME IS NULL OR B.NAME IS NULL OR ISNULL(A.TEXT,'''')<>ISNULL(B.TEXT,'''') GROUP BY A.NAME,B.NAME,A.XTYPE,B.XTYPE ORDER BY 类型,匹配情况,对象名称') GO