在SQL Server中使用链接服务器数据库创建视图 [英] Create View using Linked Server db in SQL Server

查看:633
本文介绍了在SQL Server中使用链接服务器数据库创建视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在链接服务器数据库上创建视图.例如,我在[5.6.7.8]上有一个链接服务器[1.2.3.4].两个数据库服务器都是SQL Sserver2005.我想使用链接服务器上的表在[5.6.7.8]上创建View.

How can I create View on Linked Server db. For Example I have a linked server [1.2.3.4] on [5.6.7.8]. Both db servers are SQL Sserver 2005. I want to create View on [5.6.7.8] using table on linked server.

在使用全名[1.2.3.4] .db.dbo.table创建时,出现此错误.

On creating using full name, [1.2.3.4].db.dbo.table, I am getting this error.

SQL执行错误.

已执行的SQL语句:SELECT * FROM 1.2.3.4.db.dbo.table (您可以看到括号不存在.) 错误源:.Net SqlClient数据提供程序 错误消息:'0.0'附近的语法不正确. ---> IP地址的一部分.

Executed SQL statement: SELECT * FROM 1.2.3.4.db.dbo.table (YOu can see brackets are not there.) Error Source: .Net SqlClient Data Provider Error Message: Incorrect syntax near '0.0'. ---> part of IP address.

我只是在ManagementStudio中创建它,而不使用它,因为它尚未创建.我已经更改了IP.在图像中,您可以看到IP周围没有括号,但是我给出了,错误地将这些括号删除了.

I am just creating this in ManagementStudio, not using it because it is not created yet. I Have changed IP. In image you can see there are not brackets around IP but I given it and on error these brackets are removed.

谢谢.

推荐答案

您需要使用四部分限定名称:linkedserver.database.schema.table

You need to use the four part qualified name: linkedserver.database.schema.table

SELECT * FROM [1.2.3.4].Northwind.dbo.Customers

这是有关访问对象名称的MSDN文章.

Here is an MSDN article about accessing object names.

您可能想尝试手动创建视图,而不是使用SQL管理工具:

You might want to try manually creating the view, rather than using the SQL Management tools:

CREATE VIEW [dbo].[sywx]
AS
    SELECT  *
    FROM    [1.2.3.4].Atia.dbo.IpPbxDCR
GO

如果可能的话,我还建议您为链接服务器使用一个名称,而不要使用IP地址.

I also recommend that you use a name, if possible, for the linked server rather than using the IP address.

这篇关于在SQL Server中使用链接服务器数据库创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆