SQL Server错误:最大前缀数。使用连接语法,最大值为3.

时间:2011-08-22 18:53:16

标签: sql-server sql-server-2000 linked-server

尝试运行跨服务器更新:

UPDATE ASILIVE.CustomerManagementSystem.dbo.Sessions
SET ASILIVE.CustomerManagementSystem.dbo.Sessions.VarianceAmount=Variances.VarianceAmount
FROM ASILIVE.CustomerManagementSystem.dbo.Sessions
    INNER JOIN Variances
    ON ASILIVE.CustomerManagementSystem.dbo.Sessions.SessionGUID = Variances.SessionGUID
WHERE ASILIVE.CustomerManagementSystem.dbo.Sessions.VarianceAmount <> Variances.VarianceAmount

给出错误:

Msg 117, Level 15, State 2, Line 5
The number name 'ASILIVE.CustomerManagementSystem.dbo.Sessions' contains 
more than the maximum number of prefixes. The maximum is 3.

是什么给出了?


另见


不重要的研究:

我尝试将事物随机混淆到s

UPDATE ASILIVE.CustomerManagementSystem.dbo.Sessions s
SET s.VarianceAmount=Variances.VarianceAmount
FROM ASILIVE.CustomerManagementSystem.dbo.Sessions s
    INNER JOIN Variances
    ON s.SessionGUID = Variances.SessionGUID
WHERE s.VarianceAmount <> Variances.VarianceAmount

但这不起作用:

Msg 117, Level 15, State 2, Line 5
The number name 'ASILIVE.CustomerManagementSystem.dbo.Sessions' contains 
more than the maximum number of prefixes. The maximum is 3.

Hamlin建议添加括号:

UPDATE [ASILIVE].[CustomerManagementSystem].dbo.Sessions
SET [ASILIVE].[CustomerManagementSystem].dbo.Sessions.DisciplineVarianceAmount=DisciplineVariances.VarianceAmount
FROM [ASILIVE].[CustomerManagementSystem].dbo.Sessions
    INNER JOIN DisciplineVariances
    ON [ASILIVE].[CustomerManagementSystem].dbo.Sessions.SessionGUID = DisciplineVariances.SessionGUID
WHERE [ASILIVE].[CustomerManagementSystem].dbo.Sessions.DisciplineVarianceAmount <> DisciplineVariances.VarianceAmount

但这不起作用:

Msg 117, Level 15, State 2, Line 5
The number name 'ASILIVE.CustomerManagementSystem.dbo.Sessions' contains
more than the maximum number of prefixes. The maximum is 3.

2 个答案:

答案 0 :(得分:7)

通常,您需要在链接服务器名称周围添加括号。

[ASILIVE].[CustomerManagementSystem].dbo.Sessions

编辑 - 再试一次

UPDATE S
SET DisciplineVarianceAmount = Variances.VarianceAmount
FROM [ASILIVE].[CustomerManagementSystem].dbo.Sessions as S
    INNER JOIN Variances ON S.SessionGUID = Variances.SessionGUID
WHERE S.VarianceAmount <> Variances.VarianceAmount

答案 1 :(得分:5)

你真的喜欢打字吗? : - )

UPDATE s
  SET s.DisciplineVarianceAmount = v.VarianceAmount
  FROM [ASILIVE].[CustomerManagementSystem].dbo.Sessions AS s
  INNER JOIN dbo.Variances AS v
  ON s.SessionGUID = v.SessionGUID
  AND s.VarianceAmount <> v.VarianceAmount;

请注意,如果当前的差异金额为NULL,您可能需要说明此处的操作。