Create View using Linked Server db in SQL Server

Kashif picture Kashif · Mar 22, 2010 · Viewed 74.5k times · Source

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.

EDIT:

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

SQL Execution Error.

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.

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.

Thanks.

Answer

Ryan picture Ryan · Mar 22, 2010

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

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

Here is an MSDN article about accessing object names.

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

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