视图和存储过程比较
1 CREATE proc p_compdb 2 @db1 sysname, --第一个库 3 @db2 sysname --第二个库 4 as 5 exec(' 6 select 类型=case isnull(a.xtype,b.xtype) when ''V'' then ''视图'' else ''存储过程'' end 7 ,匹配情况=case 8 when a.name is null then ''库 ['+@db1+'] 中无'' 9 when b.name is null then ''库 ['+@db2+'] 中无'' 10 else ''结构不同'' end 11 ,对象名称=isnull(a.name,b.name),a.text as atext, b.text as btext 12 from( 13 select a.name,a.xtype,b.colid,b.text 14 from ['+@db1+']..sysobjects a,['+@db1+']..syscomments b 15 where a.id=b.id and a.xtype in(''V'',''P'') and a.status>=0 16 )a full join( 17 select a.name,a.xtype,b.colid,b.text 18 from ['+@db2+']..sysobjects a,['+@db2+']..syscomments b 19 where a.id=b.id and a.xtype in(''V'',''P'') and a.status>=0 20 )b on a.name=b.name and a.xtype=b.xtype and a.colid=b.colid 21 where a.name is null 22 or b.name is null 23 or isnull(a.text,'''') <>isnull(b.text,'''') 24 --group by a.name,b.name,a.xtype,b.xtype 25 --order by 类型,匹配情况,对象名称')