SQL is the NULL value instead tag

In SQL, NULL often encounter data, since programming languages such as C, C ++, C #, JAVA and others have NULL, then the two will be granted equivalence, in fact, the two are not equivalent. In C, C ++, C #, JAVA and other language, NULL as the value actually exists. For example, to create an object in C # Object, we can be assigned to null, but this time one thing is clear is that this data is of type Object. However, in SQL, NULL data type is unknown, it might argue that the database columns in the design, we have to set type, such as NVARCHAR, VARCHAR, INT and other types, and checked PERMIT after] NULL, NULL data can be stored, so the value is NULL. However, the actual is not the case, allowing NULL just say this data can be labeled as NULL, NULL but is not actually true value, but NULL tag.

If we have this understanding, we query data, the difference will be very easy to understand = NULL and IS NULL's.

= NULL this SQL statement, the equal sign represents the judgment of value, it must be able to judge the value, while NULL is a marker, it is impossible to judge them. [] = NULL then calculated from the tangle is what value it? It is UNKNOWN. Is an uncertain value. Since when is uncertain, so as to = NULL query WHERE condition is the result of lack of expected.

We can be so understanding, judgment of the equal sign is a Boolean type, normal logic is the only true and false, but the actual situation in Central Africa that is false is true can not cover all possible, because there is a uncertain. For example, a person walking in front, normal logic is this man who is not woman, but in the absence of discrimination to determine, is male or female is uncertain, in other words sentence, said there is a third state. The three states = NULL like this. Similarly use> NULL, <NULL, <> NULL value such type judgment would be the case. So when a part of the logic for SQL = NULL so that we will have unexpected results.

The use of IS NULL is not the case, IS is a logical decision or thing is NO, NULL is a marker, it is determined whether the IS NULL NULL data tag. IS NULL can be said as a whole, it is to determine whether there is NULL data.

Analyzing the data with a logic for incorporation in the unknown will affect the actual results.

If it is NOT a logical, easy to understand this, it is "no." If you have NOT NULL, data that logic is not NULL.

If AND logic, as long as there is false, then the result is necessarily false. In the absence of false, as long as there is unkown certainly is unknown. Only when all true is true. I.e., priority is false> unkown> true.

If it is OR logic, as long as there is true, then the result is necessarily true. If not true and there are unknown it is invariably unknown. I.e., priority is true> unkown> false.

Above refer to "SQL Advanced Course"

Reproduced in: https: //www.cnblogs.com/sparkleDai/p/11039708.html

Guess you like

Origin blog.csdn.net/weixin_34293246/article/details/93580068