如何批量更新视图? [英] How to do bulk update of views?
问题描述
我的数据库有大约 30 个视图,其中大部分都引用了此服务器上的另一个数据库(称为 DB1
).
My database has about 30 views, most of which have a reference to another database on this server (call it DB1
).
现在,不考虑原因,我需要将所有这些视图更新到 DB2
,也在本地服务器上.
Now, without going into the reasons why, I need to update all those views to DB2
, also on the local server.
我不想在每个视图上手动执行此操作.是否有一些我可以运行的 SQL 查询将在我的所有视图中将所有出现的字符串 'DB1' 替换为 'DB2'?
I would hate to have to do this manually on each view. Is there some SQL query I can run that will replace all occurrences of the string 'DB1' with 'DB2' in all my views?
推荐答案
导航到视图文件夹,现在按 F7(对象资源管理器详细信息)从右侧窗格中选择您想要的所有视图,右键单击--> 脚本视图为--> DROP and CREATE TO
--> 新的查询窗口.在那里将 DB1 更改为 DB2,瞧
navigate to the views folder, press F7 (Object Explorer Details) now from the right pane select all the views you want, right click-->script view as--> DROP and CREATE TO
--> new query window. In there change DB1 to DB2 and voila
看图片
这篇关于如何批量更新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!