Follow SQLMaster on Twitter
Welcome to SqlServer-QA.net Sign in | Help

Script out Procedures and Functions - Part 2


 

Part 1 uses information_Schema.routines view and this is based on sp_helptext

 

declare @sps table(texts varchar(8000))

insert into @sps

select 'sp_helptext '''+name+'''' from sysobjects where xtype in ('p','fn')

order by xtype,name

 

create table scripts(sps varchar(8000))

 

declare @texts varchar(1000)

select @texts=min(texts)from @sps

while @texts>''

Begin

EXEC('insert into scripts(sps) EXEC '+ @texts)

insert into scripts(sps) select 'GO'

select @texts=min(texts)from @sps where texts>@texts

End

EXEC master..xp_cmdshell 'bcp "select * from dbname..scripts" queryout "c:\scripts.txt" -c' 

drop table scripts

Published Thursday, December 13, 2007 11:57 AM by Madhivanan
Filed under: ,

Comments

# Script out Procedures and Functions - Part 2

Part 1 uses information_Schema.routines view and this is based on sp_helptext declare @sps table ( texts

Thursday, December 13, 2007 7:22 AM by Other SQL Server Blogs around the Web

# Script out Procedures and Functions - Part 2

Part 1 uses information_Schema.routines view and this is based on sp_helptext declare @sps table ( texts

Thursday, December 13, 2007 8:34 AM by SSQA.net - SqlServer-QA.net
Anonymous comments are disabled