3

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Miles
  • 5,646
  • 18
  • 62
  • 86

3 Answers3

13

Check this

You can surround server name with brackets

Community
  • 1
  • 1
Jhonny D. Cano -Leftware-
  • 17,663
  • 14
  • 81
  • 103
2

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

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • 2
    I get this: "Could not find server 'ServerName\InstanceName' in sysservers. Execute sp_addlinkedserver to add the server to sysservers". – tjmoore Jul 30 '12 at 09:00
1

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
Keith Hoffman
  • 608
  • 5
  • 16