简体   繁体   中英

Changing Database Name In Stored Procedures

I need to change the database name in SQL SERVER 2008 and use it in another project. However it consist hundreds of stored procedures and the name of the database should be changed in the stored procedures as well. Is there any way to do this?

If you right mouse click a Database and choose Tasks->Generate Scripts. Go through the Wizard and it will create a SQL script for you. Make sure that you select all of the necessary options eg Create Database, Stored Procedures etc. Once finished, you'll have a big script. Find and replace the database name.

I would suggest that you export all your stored procedures as sql-files and then take a nice texteditor (like Notepad++) and make a file-search&replace-action to change all the names referenced inside the sql-files.

There is no other way around as far as I can say :-(

接下来,我将做一件事:我将通过Management Studio为数据库生成所有脚本( Right Click on DB -> Tasks -> Generate scripts ),然后替换数据库名称( Ctrl + H )。

Right click on the database, Tasks -> Generate scripts, select stored procedure, and open the scripts in sql editor.

Search and replace the database or string names. replace Create procedure with Alter procedure. Compile and done.

There is no way of doing this automatically. You would have to manually change every stored procedure.

Do you really need to change the name?

Wouldn't it be better to keep everything the same and use a different server or server instance? Are you going to have to maintain database changes through these two datbases with the different names?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM