Solved

Edit all views and stored Procedures

Posted on 2011-09-07
4
322 Views
Last Modified: 2012-05-12
We are planning to migrate to SQL Server 2008 from 2005. We also wanted to change the database names while doing this.But the problem is, we have these database names hard-coded in the views and stored procedures.
Can we write a script to rename all the database names inside these views and stored procedure instead of going to each one of them and change it ?
I tried to Generate scripts using SSMS for all the ones that I need to change and replaced the database names using the text editor and then ran this script in Management Studio which did not work.
Any ideas ?

Thanks,
TH

0
Comment
Question by:supportrp
4 Comments
 
LVL 15

Assisted Solution

by:faiga16
faiga16 earned 167 total points
Comment Utility
0
 
LVL 6

Accepted Solution

by:
markterry earned 167 total points
Comment Utility
That should work.

First off ... Do a backup.

Generate Scripts, then change the database name on the actual database, then do a find and replace on the generated script (must be an overwriting script, like drop and create, or alter) and replace prior database name with new database name.

This will not work if you do not change the database name before running the script.
0
 
LVL 5

Assisted Solution

by:DavidMorrison
DavidMorrison earned 166 total points
Comment Utility
Hi

In ssms right click the DB, select tasks then generate scripts. this will let you script the entire DB into a new query window. Once it has done this just do a find and replace of the old DB name to the new one and you're done

Thanks

Dave
0
 
LVL 1

Author Closing Comment

by:supportrp
Comment Utility
Synonym option doesn't work for my scenario though it is one of the ways. I will have to try the other option after the migration. But I am sure this will work.

Thanks for the quick responses!


TH
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 22
SQL Help joining two tables 7 33
Record extraction 3 12
SQL Server Error Log - logging period 1 14
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now