SQL Server 错误:“最大前缀数。”最大值为 3"使用子选择语法

发布于 2024-08-24 03:51:55 字数 1039 浏览 5 评论 0 原文

尝试运行跨服务器更新:

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

出现错误:

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.

什么原因?


注意:将查询重新排列为可读性较差连接形式:

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

不会给出错误。

另请参阅

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海不蓝 2024-08-31 03:51:55

是的,事情就是这样。您不能拥有超过三个前缀,因此当超过 3 个时(主要是加入其他服务器时),您必须使用别名。从 Sql Server 7 开始(也许在我不记得 6.5 之前)就是这样。

如果您想让代码在使用别名时更具可读性,请指定一个更有意义的别名,这将使它更容易理解。

例子:

SELECT 

production_accounting_clients.[ClientName]

FROM Production.Accounting.dbo.Clients production_accounting_clients

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文