0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dmoore1181
  • 1,793
  • 1
  • 25
  • 57

2 Answers2

2

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
0

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.

Maverick
  • 1,167
  • 1
  • 8
  • 16