SQL - Connect to Linked Server with Named Instance

帅比萌擦擦* 提交于 2019-12-18 07:01:48

问题


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


回答1:


Check this

You can surround server name with brackets




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/794095/sql-connect-to-linked-server-with-named-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!