programing

T-SQL에서 같지 않은 경우! = 또는 <>를 사용해야합니까?

nasanasas 2020. 9. 29. 07:55
반응형

T-SQL에서 같지 않은 경우! = 또는 <>를 사용해야합니까?


내가 본 SQL용도가 모두 있다는 !=<>위해 동일하지 . 선호하는 구문은 무엇이며 그 이유는 무엇입니까?

에게 생각 나게 !=하기 때문에 나는 좋아한다 .<>Visual Basic


기술적으로 SQL Server AKA T-SQL을 사용하는 경우 동일하게 작동합니다. 저장 프로 시저에서 사용하는 경우 다른 하나를 사용하는 성능 이유가 없습니다. 그런 다음 개인 취향에 따라 결정됩니다. ANSI 규격이므로 <>를 사용하는 것을 선호합니다.

다양한 ANSI 표준에 대한 링크를 찾을 수 있습니다.

http://en.wikipedia.org/wiki/SQL


대부분의 데이터베이스는 !=(인기 프로그래밍 언어) 및 <>(ANSI)를 지원합니다.

!=<>다음을 모두 지원하는 데이터베이스 :

ANSI 표준 연산자를 독점적으로 지원하는 데이터베이스 :

  • IBM DB2 UDB 9.5 : <>
  • Microsoft Access 2010 : <>

'<>'로부터 인 SQL-92 표준'!='A는 고유 T-SQL 연산자. 다른 데이터베이스에서도 사용할 수 있지만 표준이 아니기 때문에 사례별로 가져와야합니다.

대부분의 경우 연결중인 데이터베이스를 알 수 있으므로 실제로는 문제가되지 않습니다. 최악의 경우 SQL에서 검색 및 교체를 수행해야 할 수 있습니다.


ANSI SQL 표준은 <>"같지 않음"연산자로 정의합니다 .

http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt ( 5.2 <token> and <separator>)

!=ANSI / SQL 92 표준에 따른 연산자 는 없습니다 .


<> SQL-92 표준에 따른 유효한 SQL입니다.

http://msdn.microsoft.com/en-us/library/aa276846(SQL.80).aspx


둘 다 유효하고 SQL Server 와 관련하여 동일합니다 .

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/not-equal-to-transact-sql-exclamation


마이크로 소프트 자신이 선호하는 것 같습니다 <>!=자신의 테이블 제약에서 입증. 나는 !="같지 않음"이라고 명확하게 읽었 기 때문에 개인적으로 사용하는 것을 선호 하지만 [field1 != field2], constrait로 입력 하고 저장하면 다음에 쿼리 할 때로 표시됩니다 [field1 <> field2]. 이것은 그것을하는 올바른 방법이 나에게 말한다 <>.


!=는 ANSI가 아니지만 읽을 수있는 언어로서 SQL의 진정한 정신에 더 가깝습니다. 그것은 동등하지 않다고 비명을 질렀습니다. <>나에게 (보다 작음, 이상) 이상하다고 말합니다. 나는 그 의도가 같지 않다는 것보다 작거나 크다는 것을 압니다. 그러나 그것은 정말 단순한 것을 말하는 정말 복잡한 방법입니다.

I've just had to take some long SQL queries and place them lovingly into an XML file for a whole bunch of stupid reasons I won't go into.

Suffice to say XML is not down with <> at all and I had to change them to != and check myself before I riggedy wrecked myself.


You can use whichever you like in T-SQL. The documentation says they both function the same way. I prefer !=, because it reads "not equal" to my (C/C++/C# based) mind, but database gurus seem to prefer <>.


I understand that the C syntax != is in SQL Server due to its Unix heritage (back in the Sybase SQL Server days, pre Microsoft SQL Server 6.5).


One alternative would be to use the NULLIF operator other than <> or != which returns NULL if the two arguments are equal NULLIF in Microsoft Docs. So I believe WHERE clause can be modified for <> and != as follows:

NULLIF(arg1, arg2) IS NOT NULL

As I found that, using <> and != doesn't work for date in some cases. Hence using the above expression does the needful.


I preferred using != instead of <> because sometimes I use the <s></s> syntax to write SQL commands. Using != is more handy to avoid syntax errors in this case.


They are both accepted in T-SQL. However, it seems that using <> works a lot faster than !=. I just ran a complex query that was using !=, and it took about 16 seconds on average to run. I changed those to <> and the query now takes about 4 seconds on average to run. That's a huge improvement!


Although they function the same way, != means exactly "not equal to", while <> means greater than and less than the value stored.

Consider >= or <=, and this will make sense when factoring in your indexes to queries... <> will run faster in some cases (with the right index), but in some other cases (index free) they will run just the same.

This also depends on how your databases system reads the values != and <>. The database provider may just shortcut it and make them function the same, so there isn't any benefit either way.PostgreSQL and SQL Server do not shortcut this; it is read as it appears above.

참고URL : https://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-t-sql

반응형