How are NULLs stored in a database?

后端 未结 5 844
野性不改
野性不改 2021-01-04 11:25

I\'m curious to know how NULLs are stored into a database ?

It surely depends on the database server but I would like to have an general idea about it.


5条回答
  •  天涯浪人
    2021-01-04 12:04

    IBM Informix Dynamic Server uses special values to indicate nulls. For example, the valid range of values for a SMALLINT (16-bit, signed) is -32767..+32767. The other value, -32768, is reserved to indicate NULL. Similarly for INTEGER (4-byte, signed) and BIGINT (8-byte, signed). For other types, it uses other special representations (for example, all bits 1 for SQL FLOAT and SMALLFLOAT - aka C double and float, respectively). This means that it doesn't have to use extra space.

    IBM DB2 for Linux, Unix, Windows uses extra bytes to store the null indicators; AFAIK, it uses a separate byte for each nullable field, but I could be wrong on that detail.

    So, as was pointed out, the mechanisms differ depending on the DBMS.

提交回复
热议问题