I'm using SQL Server 2008, and I would like to copy stored procedures from one database to another. How?
-
Just use the Management Studio to generate a script for the stored procedures, save the script to a file then run it on the other SQL Server.
From memory you right click the database and under All Tasks is Generate Scripts or something like that. This will produce the Transact-SQL to create whatever you select.
JR
jhayes : is there an import/export wizard in 2008? 2k had the option to copy objects.From John Rennie -
Right click on the SP under the DB and click Script Stored Procedure As > CREATE To > File, it will create an SQL script file, then run that script on the other database.
Joel Coel : Just be careful, because this script often has a _USE [Database]_ command at the top. If the new database is named something different, you'll want to update that as well.Dan : That is true, thanks.mrdenny : +1 for step by step instructions.From Dan -
Here is a query (set output to text) to return the stored procedures :
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE='PROCEDURE'mrdenny : This doesn't always work, depending on text wrap settings, and the width of the code. It can under certain setups give you funky CRLFs in the output code, as can sp_helptext.From Ash Machine -
There are options in SSMS to make it generate permissions for users as well - that's handy.
Tools>options>scripting
You can also script multiple by clicking 'stored procedures' in your Object Explorer pane and then multi selecting procedures in the Object Explorer Details window. Right click the selected procedures and you're ready to go.
I prefer redgate's SQL Compare.
From Sam -
The answers above are all good and will work. The issue is (in my world, anyway): Where are your sprocs?
In my case, we have one kit of sprocs in the app db (business logic, etc), and another set of system management sprocs in master.
The kicker for me is having to move (and keep in sync) the sprocs in master ....
From samsmith
0 comments:
Post a Comment