Database question anyone help me thanks.

2008-04-22 11:38 pm
What is the purpose of nulls and what do they represent? i know primary key canot acept nulls rite? but why?

回答 (2)

2008-04-24 4:48 pm
✔ 最佳答案
NULL means nothing or undefined value. NULL is not empty string. NULL is not 0. NULL is not -1.


Technically most object in a database is a list of pointers pointing to a data storage location. NULL means that there is no pointer at all. So NULL save some storage space. If I have a column that pre-allocates storage space (such as CHAR 1024), a null value can save these 1000 bytes, comparing to an empty stringIn those tables that have millions records of address, photo, and other optional data, the use of NULL really makes a big difference.

Since NULL also means undefined in a way. You cannot compare an object will NULL. For example if you sort a column that allows null, some database will put NULL at the top while others in the end. If you set a critiria such as

   select * from tableX where anInteger < 10

those records with a NULL value will never show up, no matter it is <10  >10  =10  or <>10.


Primary Key (refer as PK) cannot be NULL because PK mush be unique. In most database, PK is also the cluster index that is used to sort the table. If the sorting of a column differs from database to database, it would be a disaster. Other than this, there is no other technical reason that a PK cannot be NULL. If PK allows NULL, then there can only be 1 record that can have NULL, so it is pretty pointless anyway.

PK cannot be NULL is more of a concept in life rather than a technical limitation. PK is the most important identity of a record, just like the ID of a passport or the social security number. Think about a passport that do not have an ID.
2008-04-23 4:41 am
Null value represents nothing. When we use to compare, it would be the lowest value we have. It would be used to position the searching pointer from the beginning of the list. For example, set null values to the primary key and then start searching for comparison.

Hence, the primary key cannot be null value.


收錄日期: 2021-04-16 23:20:14
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080422000051KK01163

檢視 Wayback Machine 備份