SQL Server Error: “maximum number of prefixes. The maximum is 3” with subselect syntax

冷暖自知 提交于 2019-12-11 01:09:24

问题


Trying to run a cross-server update:

UPDATE asilive.Contoso.dbo.lsipos
SET PostHistorySequencenNmber = (
    SELECT TransactionNumber 
    FROM Transactions 
    WHERE Transactions.TransactionDate = 
         asilive.CMSFintrac.dbo.lsipos.TransactionDate)

Gives the error:

Server: Msg 117, Level 15, State 2, Line 5
The number name 'asilive.Contoso.dbo.lsipos' contains more than 
the maximum number of prefixes. The maximum is 3.

What gives?


Note: Rearranging the query into a less readable join form:

UPDATE asilive.Contoso.dbo.lsipos
SET PostHistorySequenceNumber = B.TransactionNumber
FROM cmslive.Contoso.dbo.lsipos A
    INNER JOIN Transactions B
    ON A.TransactionDate = B.TransactionDate

does not give an error.

See also

  • SQL Server Error: maximum number of prefixes. The maximum is 3. with join syntax
    (Deals with join syntax; this question deals with sub-select syntax)

回答1:


Yes, that is just the way it is. You can't have more than three prefixes, so you have to use an aliases when you go over 3 (mainly when joining to other servers). It's been that way since Sql Server 7 (and maybe before I can't remember on 6.5).

If you want to make your code more readable when using aliases, specify a more meaningful alias which will make it a lot easier to follow.

Example:

SELECT 

production_accounting_clients.[ClientName]

FROM Production.Accounting.dbo.Clients production_accounting_clients


来源:https://stackoverflow.com/questions/2404503/sql-server-error-maximum-number-of-prefixes-the-maximum-is-3-with-subselect

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