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
  • 704,970
  • 168
  • 1,303
  • 1,425
dmoore1181
  • 1,493
  • 1
  • 19
  • 48

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,137
  • 1
  • 8
  • 15