Reputation: 3
We are migrating the server and the time of migration we are changing existing databasename to new name. my problem is I have created multiple views and Procs in that database tables. Now I need to replace/modifi in all view/Procs with new database name. Is there any possibility to change or replace existing dn name to new db name in all views/procs in dynamiclly?
Upvotes: 0
Views: 742
Reputation: 9638
You can run this query, after get result run NewModifiedQuery column as a query
SELECT a.definition OldCreationQuery
,Replace ((REPLACE(definition,'OldDatabaseName','NewDatabaseName')),'Create','ALTER') NewModifiedQuery
FROM sys.sql_modules a
where a.definition like '%OldDatabaseName%'
Upvotes: 3