How to correctly understand null in SQL

Source: Internet
Author: User

in SQL statements, the null value is different from the space in the character column, the zero in the number, and the null ASCII character in the character column. when the DBMS finds a null value in a column, it translates it into undefined or unavailable. DBMS cannot make null assumptions in a column, nor can it assume that the null value is equal to null. The possible cause for a column to become null is: (1), and the value does not exist; (2), the value is unknown; (3), the column is unavailable to the table. therefore, the null value should be treated as an operator rather than a value. when a DBMS finds a null value in a column in a row of a table, the DBMS knows that the data is lost or unavailable.
in one sentence, null indicates that the value is "unknown" because it may not exist or be unavailable, or because the value is unknown.
"null" in each environment (I don't know how to name these things. It's a null value for the moment !) A simple explanation:
1: True null values (null in SQL)
equivalent to "no input value ", can appear in most types of fields (if there are no other constraints), SQL Server is expressed as null, displayed, manually enter Ctrl + 0 in the SQL Server Enterprise Manager. It corresponds to system. dbnull. Value in. net. In the T-SQL command, to determine whether a value is null, use "is null" instead of "= NULL"; to handle a null value, there is an isnull function that replaces null with the specified value. Use ADO. the null value obtained from the database cannot be automatically converted to a null string or a nothing. You must manually check the value if system is obtained. dbnull. value is assigned to the Data Object nothing or other custom meaningful values.
2: empty string (zero-length string), which only appears in string type (such as nvarchar) fields. It is expressed as ''in SQL Server and displayed as blank, manually enter a cell in the SQL Server Enterprise Manager. It corresponds to system. String. Empty in. net, which is commonly used "". Processing empty strings in T-SQL commands is no different from processing general strings. The Null String obtained from the database using ADO. NET is no different from the general string.

3. VB. net; it actually corresponds to C #. NET Null (note that this null is C #. net, rather than SQL Server), they are in. net is a null reference value that does not reference any object.

In SQL Server, it may be stored as a true null value (for example, when updating a field value of the string type) according to different context environments ), it is also possible to call the custom default values in SQL Server (for example, to pass a stored procedure parameter with a default value), or it may be caused by the failure of type conversion. net exception. Therefore, when using ADO. Net to store data to SQL Server, you must be careful when using nothing.
4. The difference between the undefined value and null is:
Generally, the undefined value can be used in the following cases:
(1) The object property does not exist,
(2) declared variables but never assigned values.
Release the reference and use NULL for operations such as variable value in the trace result.

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.