Thursday, March 22, 2012

Copying Stored Procedures from one database to another

How do i copy Stored Procedures from one SQL Express database to another?

One way is, in Object Explorer (You do have SQL Server Management Studio Express, don't you), expand the Database, expand [Programability], expand [Stored Procedures], then right click on the stored procedure you want. One of the choices will be to [Script AS ...], choose [CREATE], then choose [File]. Save the file, copy the file, take to the other server, open it in Object Explorer, and then execute the file.

|||Thanks so much for your response Arnie. The part I'm confused about is importing it into the target database. I'm not sure how to do it...

I do use SQL Express Management Studio - from your explanation, I know how to export a stored procedure to a file. I'm unsure of how to import this file...
|||

Be sure to save the file with an extension of ".sql".

Then, in SSMSE, Click on [File], [Open], [File...] and navigate to and select your file. when it opens, then execute the code.

|||I'll just have to rename the database in the stored procedure to that of the target database, right? So executing it this way will cause the stored procedure to be copied over? Thanks again...

I have one last question...sorry to bother you...how do i export and import multiple stored procedures? I just noticed that there are over 30 SPs...doing this for each one would be time-consuming!!
|||Never mind - i figured out how to do that.

Right-click on source database>Tasks>Generate Script>

Select the source table, select Stored Procedures, then check the required stored procedures, finally save it in a single file with a .sql extension.

Open the file, rename the database to target database name, and execute.

Thanks again...

No comments:

Post a Comment