renaming database in views,triggers, and stored procs

renaming database in views,triggers, and stored procs

Post by John » Tue, 22 Oct 2002 22:40:22



Does anyone know of a tool that will search for a word and
replace it in views, triggers, and stored procs???

Here is my situation with pubs and northwind databases
used for an example:

databases:
northwind
northwind_b
pubs
pubs_b

There is a view, trigger, and stored proc in pubs that
references the database northwind by means of the code
reading northwind.dbo.table.column

I Backup pubs
I Restore pubs to a new database called pubs_B

The view, trigger, and stored proc now need to point to
northwind_b so the code needs to be
changed to northwind_b.dbo.table.column

Is there an easy way to do this for a whole bunch of code?
I can do it manually but it takes forever.

Thanks.

 
 
 

renaming database in views,triggers, and stored procs

Post by Dinesh.T.K » Tue, 22 Oct 2002 23:14:01


John,

The text of views,triggers and stored procedures are stored in ctext column
of syscomments table.Since updating system tables are not advisable this
method is undocumented .

From enterprise manager ( right click on the database |All tasks|Genarte sql
script) you can generate the scripts for all views,triggers and stored
procedures.Save it as a text file .Open it in a text editor and do a replace
all on 'northwind.dbo' to 'northwind_b.dbo'.Execute the modified script
against the database.

Dinesh, SQL Server MVP
--
--
SQL Server FAQ at
http://www.tkdinesh.com


Quote:> Does anyone know of a tool that will search for a word and
> replace it in views, triggers, and stored procs???

> Here is my situation with pubs and northwind databases
> used for an example:

> databases:
> northwind
> northwind_b
> pubs
> pubs_b

> There is a view, trigger, and stored proc in pubs that
> references the database northwind by means of the code
> reading northwind.dbo.table.column

> I Backup pubs
> I Restore pubs to a new database called pubs_B

> The view, trigger, and stored proc now need to point to
> northwind_b so the code needs to be
> changed to northwind_b.dbo.table.column

> Is there an easy way to do this for a whole bunch of code?
> I can do it manually but it takes forever.

> Thanks.


 
 
 

renaming database in views,triggers, and stored procs

Post by Sue Hoegemeie » Tue, 22 Oct 2002 23:17:30


Black Moshannon has a tool called Speed Ferret that does this:
http://www.moshannon.com/speedferret.html

-Sue



Quote:>Does anyone know of a tool that will search for a word and
>replace it in views, triggers, and stored procs???

>Here is my situation with pubs and northwind databases
>used for an example:

>databases:
>northwind
>northwind_b
>pubs
>pubs_b

>There is a view, trigger, and stored proc in pubs that
>references the database northwind by means of the code
>reading northwind.dbo.table.column

>I Backup pubs
>I Restore pubs to a new database called pubs_B

>The view, trigger, and stored proc now need to point to
>northwind_b so the code needs to be
>changed to northwind_b.dbo.table.column

>Is there an easy way to do this for a whole bunch of code?
>I can do it manually but it takes forever.

>Thanks.

 
 
 

1. Deferred name resolution in stored procs and triggers but not views

After upsizing one of my SQL Server 6.5 systems to 7.0 I noticed that
the logs reported errors in upsizing my views. My views are of the form

CREATE VIEW dbo.vwAView AS
-- vwBView and vwCView are views
SELECT ColA,ColB FROM dbo.vwBView
UNION ALL
SELECT ColA,ColB FROM dbo.vwCView

The errors mentioned 'Invalid object name 'dbo.vwBView' and
'dbo.vwCView''. (Note, vwBView and vwCView come alphabetically after
vwAview and were upsized successfully). All views exist in my 6.5
database. My simple workaround was to script the views from 6.5 and
submit them to my 7.0 system after the upsizing.

This got me wondering. In 7.0 I can create stored procedures and
triggers referencing objects which don't yet exist (deferred name
resolution) but I can't use the same feature when creating views. Why
would this be so ? Is this by design ? If so, can anyone explain the
apparent inconsistency ?

Thanks,
--
Nayan Raval

2. excluding seconds from the query

3. Unable to Design tablles, view and stored procs etc using Data View

4. How to show only non-system tables (ADOX) from Access and Excel?

5. Renaming of Stored Procs

6. DBASE III File Access

7. Renaming A Column And Stored Procs?

8. archive data

9. VIEWS OR STORED PROCS?

10. Views Vs Stored Procs (with ASP)

11. Locally partitioned views and stored procs

12. benifits to views over stored procs?

13. VIEWS OR STORED PROCS?