How to reference a sql server with a backslash (\) in its name?
Solution 1
In 4 part names, the first part if the name of a linked server (ie. a metadata object), not the name of a server (ie. a host name). So you can name your linked server FOO and have him point at the host BAR, or at the instance FOO\BAR. And even if you name the linked server object to contain a slash, you can still use it in a multi-part name by simply quoting the name:
SELECT TOP 1 *
FROM [DevServerB\2K5].master.sys.tables
Solution 2
Try using square brackets:
SELECT TOP 1 *
FROM [DevServerB\2K5].master.sys.tables
Bill Paetzke
Out of the box, yet practical. Mature technologist who builds SaaS backends, architects features and platforms, manages projects, and leads teams. Has interest in the business side of tech; always has an eye on cost; excited by being close to revenue generating projects.
Updated on July 09, 2022Comments
-
Bill Paetzke almost 2 years
Givens:
- One SQL Server is named:
DevServerA
- Another is named:
DevServerB\2K5
Problem:
From
DevServerA
, how can I write a query that referencesDevServerB\2K5
?I tried a sample, dummy query (running it from
DevServerA
):SELECT TOP 1 * FROM DevServerB\2K5.master.sys.tables
And I get the error:
Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '\.'.
However, I know my syntax is almost correct, since the other way around works (running this query from
DevServerB\2K5
):SELECT TOP 1 * FROM DevServerA.master.sys.tables
Please help me figure out how to reference
DevServerB\2K5
fromDevServerA
. Thanks. - One SQL Server is named: