Miles
Miles

Reputation: 5736

SQL - Connect to Linked Server with Named Instance

How do I connect to a named instance of a linked SQL server.

If its not linked, I would do the following:

ServerName.DatabaseName.dbo.TableName

If it is linked, I would assume the following:

ServerName\InstanceName.DatabaseName.dbo.TableName

but SQL doesn't like the "\"

What is the correct syntax

Upvotes: 3

Views: 30040

Answers (3)

Martin Kafka
Martin Kafka

Reputation: 21

the correct syntax is [ServerName\InstanceName].DatabaseName.dbo.TableName.

Upvotes: 2

Keith Hoffman
Keith Hoffman

Reputation: 608

If you are using the default instance, you don't need to specify the instance name.

Example using the default instance: [MyServer].[MyDatabase].[MySchema].[MyTable]

NB: If you don't know your schema name, give [dbo] a try, since that is the default schema.

So something like this should work for you

SELECT *
FROM [MyTable] t
INNER JOIN [MyLinkedServer].[MyLinkedDatabase].[MyLinkedSchema].[MyLinkedTable] lt ON lt.Id = t.Id

Upvotes: 1

Jhonny D. Cano -Leftware-
Jhonny D. Cano -Leftware-

Reputation: 18013

Check this

You can surround server name with brackets

Upvotes: 13

Related Questions