Tuesday, March 8, 2011

copy StoredProcedures between servers

MS-SQL Stored Procedures is one way that we don't need to ugly hard-code the SQL queries
in the program. However, recently, we have several versions of database update. To export procedures in old database to the new one:

In Microsoft SQL Server Management Studio, Object Explorer,
right-click on the stored procedure, select "Script Stored Procedure as CREATE TO", then either save the stored procedure as a SQL file or create a new SQL window and execute the query file in the new database. After the execution, the stored procedure is created in the new database.
But one thing to be noticed: in the head of the query file, if the names of databases are different,
then the database name need to be changed in "USE [database_name]".

No comments:

Post a Comment