T-SQL missing value null

Source: Internet
Author: User
Null missing value:
If there is null in the expression, the result is also null. The null value is never equal to other values, and it is not equal to itself. Most functions that contain null return values are also null. One exception is that the function is designed to process null first. Including isnull and coalesce.
A null value in a relational database can cause great consumption. Assume the following tables and data:
Create Table # values (K1 int identity, C1 int null)
Insert # values (C1) values (1)
Insert # values (C1) values (1)
Insert # values (C1) values (null)
Insert # values (C1) values (9)
This query:
Select * From @ values where c1 = 1
And
Select * From @ values where c1 <> 1
It may be considered that all rows in the # values table will be returned, but not actually. To obtain all rows, the null value must be taken into account. Therefore, the SQL statement should be written as follows:
Select * from # values where is C1 = 1 or C1 is null
An acceptable method to avoid null is to use a dummy element value to represent the missing value. For example, you can use "N/A" or "NV" to replace null in a string column; you can use-1 to represent the missing values in multiple numeric columns. You can use "1900-01-01" to replace dates.

The above is the Reading Notes of the book "Transact-SQL authoritative guide", thanks to the author Ken Henderson and the translator jian lian Technology China Power Press for bringing me such a classic T-SQL book.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.