Semih Yagcioglu
Semih Yagcioglu

Reputation: 4101

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?

Upvotes: 0

Views: 4532

Answers (6)

General Softwares
General Softwares

Reputation: 11

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.

Upvotes: 1

HLGEM
HLGEM

Reputation: 96572

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?

Upvotes: 0

Pavel Belousov
Pavel Belousov

Reputation: 1858

I'd make next thing: I'd generate all scripts for database by Management Studio(Right Click on DB -> Tasks -> Generate scripts), after that I'd replace name of database (Ctrl + H).

Upvotes: 1

OlafW
OlafW

Reputation: 710

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 :-(

Upvotes: 3

Neil Knight
Neil Knight

Reputation: 48547

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 e.g. Create Database, Stored Procedures etc. Once finished, you'll have a big script. Find and replace the database name.

Upvotes: 6

codingbadger
codingbadger

Reputation: 43984

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?

Upvotes: 0

Related Questions