263.生成存储过程脚本

56 阅读1分钟
select id=identity(int),text=cast(
	N'if exists(select * from sysobjects where id=object_id(N'
	+quotename(name)+N')
	drop proc '+quotename(name)+N'
	GO' as nvarchar(4000))
into ## from sysobjects
where xtype='p'
	and status>=0 
insert ##(text) select text 
from(
	select c.id,c.number,s1=0,c.text 
	from sysobjects o,syscomments c
	where o.id=c.id
		and o.xtype='p'
		and o.status>=0
	union all 
	select c.id,c.number,s1=1,'go'
	from sysobjects o,syscomments c
	where o.id=c.id
		and o.xtype='p'
		and o.status>=0
)a order by id,number,s1 
exec master.dbo.xp_cmdshell 'bcp "select text from ## order by id" queryout "c:\a.sql" /T /c',no_out_put
drop table ##