--仅代码级的比较示例set nocount ondeclare @proc1 sysname,@proc2 sysname
select @proc1='参与比较的第一个存储过程名'
,@proc2='参与比较的第二个存储过程名'create table #t1(id int identity(1,1),Text nvarchar(4000))
insert #t1 exec sp_helptext @proc1--删除存储过程头
declare @id int
select @id=id from #t1 where text like '%create proc%'+@proc1+'%'
delete #t1 where id<@id
update #t1 set text=stuff(text,1,patindex('%create proc%'+@proc1+'%',text)+11,'')
where id=@id
update #t1 set text=stuff(text,1,patindex('%'+@proc1+'%',text)+len(@proc1),'')
where id=@id--重排id
exec('alter table #t1 drop column id')
exec('alter table #t1 add id int identity(1,1)')create table #t2(id int identity(1,1),Text nvarchar(4000))
insert #t2 exec sp_helptext @proc2--删除存储过程头
select @id=id from #t2 where text like '%create proc%'+@proc1+'%'
delete #t2 where id<@id
update #t2 set text=stuff(text,1,patindex('%create proc%'+@proc1+'%',text)+11,'')
where id=@id
update #t2 set text=stuff(text,1,patindex('%'+@proc1+'%',text)+len(@proc1),'')
where id=@id--重排id
exec('alter table #t2 drop column id')
exec('alter table #t2 add id int identity(1,1)')--比较
if exists(
select 1 from #t1 a full join #t2 b on a.id=b.id
where a.id is null or b.id is null 
or a.text<>b.text)
print '不同'
else
print '相同'drop table #t1,#t2
set nocount off