SQL Server *= 运算符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/983862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server *= Operator?
提问by slf
Today while inside a client's production system, I found a SQL Server query that contained an unfamiliar syntax. In the below example, what does the *=
operator do? I could not find any mention of it on MSDN. The query does execute and return data. As far as anyone knows, this has been in the system since they were using SQL Server 2000, but they are now running 2005.
今天,在客户的生产系统中,我发现了一个包含陌生语法的 SQL Server 查询。在下面的例子中,*=
操作员做什么?我在 MSDN 上找不到任何提及。查询确实执行并返回数据。据任何人所知,自从他们使用 SQL Server 2000 以来,这一直在系统中,但他们现在正在运行 2005。
declare @nProduct int
declare @iPricingType int
declare @nMCC int
set @nProduct = 4
set @iPricingType = 2
set @nMCC = 230
--Build SQL for factor matrix
Select distinct
base.uiBase_Price_ID,
base.nNoteRate,
base.sDeliveryOpt,
IsNull(base.nPrice,0) as nPrice,
IsNull(base.nPrice,0) + Isnull(fact.nFactor,0) as nAdjPrice,
base.iProduct_ID,
fact.iPosition as fiPosition,
base.iPosition,
CONVERT(varchar(20), base.dtDate_Updated, 101) + ' ' + CONVERT(varchar(20), base.dtDate_Updated, 108) as 'dtDate_Updated',
fact.nFactor,
fact.nTreasFactor,
product.sProduct_txt ,
pfi.sPFI_Name,
mccprod.nServicing_Fee,
fact.nNoteRate as fNoteRate,
mcc.nLRA_Charge as nLRA
From
tbl_Base_Prices base, tbl_Factors fact, tbl_Product product, tbl_PFI pfi, tbl_MCC mcc, tbl_MCC_Product mccprod
Where
base.iProduct_ID = @nProduct
And base.iProduct_ID *= fact.iProduct_ID
And base.iPosition *= fact.iPosition
And base.nNoteRate *= fact.nNoteRate
And base.iPricing_Type = @iPricingType
And fact.iMCC_ID = @nMCC
And fact.iProduct_ID = @nProduct
And mcc.iMCC_ID = @nMCC
And mcc.iPFI_ID = pfi.iPFI_ID
And mccprod.iMCC_ID = @nMCC
And mccprod.iProduct_ID = @nProduct
And base.iProduct_ID = product.iProduct_ID
and fact.iPricing_Type= @iPricingType
Order By
base.nNoteRate, base.iPosition
采纳答案by HLGEM
Remove this code immediately and replace with a left join. This code does not always interpret correctly (Sometimes SQL Server decides it is a cross join) even in SQL Server 2000 and thus can give incorrect results! Also it is deprecated for the future.
立即删除此代码并替换为左连接。即使在 SQL Server 2000 中,此代码也并不总是正确解释(有时 SQL Server 决定它是交叉联接),因此可能会给出不正确的结果!此外,它在未来已被弃用。
I'm going to add that in adjusting to left joins you should remove all of those other implicit joins as well. The implicit join syntax has been obsoletesince 1992, there is no excuse for it still being in production code. And mixing implicit and explicit joins can give unexpected results.
我要补充一点,在调整左连接时,您还应该删除所有其他隐式连接。自 1992 年以来,隐式连接语法已经过时,没有任何理由让它仍在生产代码中。混合隐式和显式连接会产生意想不到的结果。
回答by Thies
It is a left outer join, =* is a right outer join.
它是一个左外连接,=* 是一个右外连接。
E.g. the following are equal;
例如以下是相等的;
SELECT * FROM Table1 LEFT OUTER JOIN Table2 ON Table1.ID = Table2.FK_ID
SELECT * FROM Table1, Table2 WHERE Table1.ID *= Table2.FK_ID
回答by Remus Rusanu
The non-ANSI syntax for outer joins (*=
and =*
) is on the official list of deprecated features that will be removed in the next version of SQL.
外连接(*=
和=*
)的非 ANSI 语法在正式的弃用特性列表中,这些特性将在下一版本的 SQL 中删除。
The following SQL Server Database Engine features will not be supported in the next version of SQL Server. Do not use these features in new development work, and modify applications that currently use these features as soon as possible.
下一版本的 SQL Server 将不支持以下 SQL Server 数据库引擎功能。不要在新的开发工作中使用这些功能,并尽快修改当前使用这些功能的应用程序。
The replacement feature is the ANSI compliant syntax of JOIN.
替换功能是JOIN 符合 ANSI 的语法。
回答by James
It's a shorthand join syntax. Take a look at this thread which covers this topic.
这是一种速记连接语法。看看这个主题,它涵盖了这个主题。
回答by Byron Whitlock
I believe those are "non-ANSI outer join operators". Your database compatibility level must be 80 or lower.
我相信那些是“非 ANSI 外连接运算符”。您的数据库兼容级别必须为 80 或更低。
回答by Scott Ivey
That's the older ANSI (ANSI-89) syntax left outer join operator. I'd recommend not using it - the ANSI syntax is more verbose and is much more readable.
这是较旧的 ANSI (ANSI-89) 语法左外连接运算符。我建议不要使用它 - ANSI 语法更冗长,可读性更强。