SQL Server: Null VS Empty String

后端 未结 8 1926
青春惊慌失措
青春惊慌失措 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:15

    How are the "NULL" and "empty varchar" values stored in SQL Server. Why would you want to know that? Or in other words, if you knew the answer, how would you use that information?

    And in case I have no user entry for a string field on my UI, should I store a NULL or a ''? It depends on the nature of your field. Ask yourself whether the empty string is a valid value for your field.

    If it is (for example, house name in an address) then that might be what you want to store (depending on whether or not you know that the address has no house name).

    If it's not (for example, a person's name), then you should store a null, because people don't have blank names (in any culture, so far as I know).

提交回复
热议问题