SQL Server: Null VS Empty String

后端 未结 8 1925
青春惊慌失措
青春惊慌失措 2020-12-04 09:34

How are the NULL and Empty Varchar values stored in SQL Server. And in case I have no user entry for a string field on my UI<

8条回答
  •  春和景丽
    2020-12-04 10:11

    Be careful with nulls and checking for inequality in sql server.

    For example

    select * from foo where bla <> 'something' 
    

    will NOT return records where bla is null. Even though logically it should.

    So the right way to check would be

    select * from foo where isnull(bla,'') <> 'something' 
    

    Which of course people often forget and then get weird bugs.

提交回复
热议问题