SQL Server null values need to be noted in place

Source: Internet
Author: User

1, null and any operator are null after operation

Normal values are generally possible operator operations, but for example: ID is listed as int, so you can: id=id+1, etc., but if the value of a column is Null,null+1=null

For example

Update Testnull
Set b=b+1
where B is null

The query found that the value of B did not change and is still null.

2. Returns False if any value is compared to null

The normal value can be "=" operation, for example, the condition usually appears: Susername= ' Zhang San ', if the value of sUserName is null, if you want to find all the names of NULL records, it can not be used: Susername=null, Because NULL is not a specific value, any value that is compared to it will return false. You can now borrow is null or is isn't null.

For example

SELECT * from Testnull where A=null --Returns an empty result set

SELECT * from testnull where B is null --return result set 2 2 NULL

Indicates that null cannot be compared with "=" and can be replaced by IS null

3. When a statistical record contains a null value, it ignores the null value

For example, the statistics function count will be different, such as Count (ID): Count Records. When a statistical record contains a null value, it ignores the null value.

4, for in the impact of different

Example query: Query the record in the Testnull table that contains the value of B in null.

SELECT * from Testnull where B in (null) --No record


In the query, NULL records are ignored, and the query can be queried with is not NULL.

5. The order of sorting is different

When an order by is used, a null value is first rendered. If you sort in descending order with DESC, the null value is displayed last.


Reference: How SQL Server determines null http://www.studyofnet.com/news/1056.html


SQL Server null values need to be noted in place

Related Article

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.