在视图中引用外部数据库?
在我正在执行维护的项目中,我引用了存储在另一台服务器上的数据库。此引用之前指向同一服务器上的数据库,但我的测试台服务器不够大,无法存储这两个数据库,因此我必须返回实时数据库。
不管怎样,无论是谁创建了这个应用程序,都使用了 SQL 视图,而且我发现在尝试编辑视图时,它无法引用外部数据库。
现有引用是myDatabase.dbo.tableName
。当我尝试将其更改为 [MyServer.com].myDatabase.dbo.tableName
时,离开编辑器会删除所有方括号,只剩下 MyServer.com.myDatabase.dbo .tableName
这不是正确的表引用。
我有什么想法可以解决这个问题吗?
In a project on which I am performing maintenance, I am referencing a database stored on another server. This reference was previously pointing at a database on the same server, but my testbed server isn't large enough to store both databases, so I'm having to refer back to the live database.
Anyway, whoever created this application made use of SQL Views, and I have found that when trying to edit the view, that it cannot reference an external database.
The existing reference is to myDatabase.dbo.tableName
. When I try to change that to [MyServer.com].myDatabase.dbo.tableName
moving away from the editor removes all of the square brackets, leaving me with MyServer.com.myDatabase.dbo.tableName
which is not a proper table reference.
Any ideas what I can do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您已经添加了一个名为“MyServer.com”的链接服务器,我建议您将其重命名为不带点的名称,MyServerCom 就可以了。如果链接服务器中的详细信息指向恰好位于该地址的服务器,那就可以了。
那么这四部分的名称可以是MyServerCom.myDatabase.dbo.tableName
It looks like you have added a linked server with the name "MyServer.com" I suggest you rename this to something without the dot, MyServerCom would be fine. Its ok if the details in the linked server point to a server that happens to be at that address.
Then the four part name can be MyServerCom.myDatabase.dbo.tableName
不要在企业管理器中编辑视图定义 - 使用查询分析器为 ALTER 视图编写脚本,进行适当的更改,然后运行脚本。
企业经理做了一些相当令人讨厌的事情。如果您使用 SSMS 来管理服务器/数据库,我同样建议编写 ALTER 脚本,而不是使用“设计”选项。
Don't edit the view definition in Enterprise Manager - use query analyser to script the view for ALTER, make the appropriate changes, and then run the script.
Enterprise manager does some fairly nasty things. I'd similarly recommend scripting an ALTER rather than using the "Design" option if you're using SSMS to manage your server/database.