SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ITX_SP_BAK


ITX_SP_BAK

Author
Message
SDB15
SDB15
SSC-Enthusiastic
SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)

Group: General Forum Members
Points: 167 Visits: 114
Comments posted to this topic are about the item ITX_SP_BAK
thorkw
thorkw
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 190
can you fix the script please?? Needs to be more vertical... Tongue
SDB15
SDB15
SSC-Enthusiastic
SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)

Group: General Forum Members
Points: 167 Visits: 114
Sorry about that. They won't let me edit it after submission. Not sure why the formatting didn't work.


/*********************************************************************************
Name: SP_BAK_MIGRATE

Author: Sean D. Brian, ITX Enterprises

Purpose: Creates a single sql install file for all stored procs in a database. Useful for migrating procs from one server to another.

----------------------------------------------------------------------------
DISCLAIMER:
This code and information are provided "AS IS" without warranty of any kind,
either expressed or implied, including but not limited to the implied
warranties or merchantability and/or fitness for a particular purpose.
-----------------------------------------------------------------------------
LICENSE:
This script is free to download and use for personal, educational,
and internal corporate purposes, provided that this header is preserved.
Redistribution or sale of this script, in whole or in part, is
prohibited without the author's express written consent.

Notes:
1) Change the Database Name below from YourDBName to the name of the target DB.
2) If XP_cmdshell is blocked, use the statement below to enable it.
--Use when XP_cmdshell gets blocked
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
3) Run the statement on the Target DB. A file will be created on the target server's c drive.
*********************************************************************************/

CREATE PROC ITX_SP_BAK

@P INT, --Back up Procs 1=yes 0=no
@FN INT, --Back up Functions 1=yes 0=no
@V INT --Back up Views 1=yes 0=no

AS
BEGIN

SET NOCOUNT ON;

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Proc_Def]') AND type in ('U'))
BEGIN
DROP TABLE [dbo].[Proc_Def]
END

DECLARE @t TABLE (Test INT)

declare c cursor local for
(
SELECT
name
FROM Sys.objects
WHERE
(
@FN=1 AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')
OR
@P=1 AND type IN (N'P', N'PC')
OR
@V=1 AND type IN (N'V')
)
AND name NOT LIKE '%sp_MSdel%' --exclude replication procs
AND name NOT LIKE '%sp_MSins%'
AND name NOT LIKE '%sp_MSupd%'
)
Declare @ID NVARCHAR(MAX)

CREATE TABLE Proc_Def (Def TEXT)

Open c
fetch next from c into @ID

while @@fetch_status = 0
BEGIN
INSERT Proc_Def
SELECT definition def
FROM sys.sql_modules sm WITH ( NOLOCK )
LEFT JOIN sys.objects so ON so.object_id = sm.object_id
WHERE so.name=@ID
--EXEC sys.sp_helptext @objname = @ID
INSERT Proc_Def
SELECT 'GO'
--Print OBJECT_DEFINITION(@ID))+' GO'
--PRINT @ID

fetch next from c into @ID
END
close c

EXEC XP_cmdshell 'BCP "SELECT def FROM YourDBName..Proc_Def" queryout "c:\SP_Script.SQL" -c -T'

DROP TABLE Proc_Def

SET NOCOUNT OFF;

END


thorkw
thorkw
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 190
much better.. thanks.
SDB15
SDB15
SSC-Enthusiastic
SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)SSC-Enthusiastic (167 reputation)

Group: General Forum Members
Points: 167 Visits: 114
Enjoy!
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22262 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search