------------------------获取所有存储过程的脚本------------------------------------

来源:互联网 发布:淘宝魅力惠 编辑:程序博客网 时间:2024/05/24 05:34

declare @proc_text varchar(max) 
DECLARE get_proc_text_cursor CURSOR FOR
SELECT
  'if object_id(N'''+ [name] +''') is not null drop proc ' + [name] +  CHAR(10) +  CHAR(13)  +  '  GO '  +  CHAR(10) +  CHAR(13) + definition + CHAR(10)  + CHAR(13) +' GO'  
FROM
 sys.sql_modules 
inner join
 sysobjects 
on
 sys.sql_modules.object_id = sysobjects.id 
and
 type='p'  OPEN get_proc_text_cursor  

FETCH NEXT FROM get_proc_text_cursor INTO @proc_text  

WHILE @@FETCH_STATUS = 0 

BEGIN
  print @proc_text     

FETCH NEXT FROM get_proc_text_cursor INTO @proc_text 

END

CLOSE get_proc_text_cursor 

DEALLOCATE get_proc_text_cursor

原创粉丝点击