简体   繁体   中英

TSQL Boolean Comparison Syntax

In TSQL is it proper to use != or should one always use <> when doing Boolean comparisons? Is there any difference in performance between the two?

No difference just like @marc_s said but if do put it in into SQL server it will just convert it to <>

Just execute the following 2 statements,

SELECT *
FROM sys.databases
WHERE database_id != 1


SELECT *
FROM sys.databases
WHERE database_id <> 1

you will see in Actual execute plan both queries will look like this, and both have same execution plans

SELECT * FROM [sys].[databases] WHERE [database_id]<>@1

There is absolutely no difference in using != OR <> OPERATORS. In terms of performance, you will see no change. I use <> just to keep me aware of mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM