473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To Null or not to Null that's my question

Reading a lot about Nulls right now I still can't find a Technical reason to
use it or not.

For what I've understand is this:

In an Ingres database a Null column has a standard extra storage of 2 Bits.
In a SQL Server database every column has a NULL-bit telling about this
column it is NULL or NOT.
That means that a varchar-empty NULLABLE column takes no space at all since
the Nullable column defines it as NULL.
In that respect: When a lot of varchar columns tend to be empty from the
space point of view make it NULLABLE.

A varchar not nullable column must be filled with a '' when it's empty. That
single quote takes 3 bits since a varchar has an overhead of 2 positions.

I am not talking about key-values although sometimes you see
reference-columns to a Master table wich is emtpy (NULL in my case)
Since the master table had no NULL-key item there is no Inner join facility.
I don't think SQL likes the outer join that much so it's clear to create an
UNKNOWN reference to the master table.
(And place this Unknown item in the master table as well).

But the rest: When should I use nulls and when do I do not ???

Arno de Jong, The Netherlands.
Jul 20 '05 #1
3 6175

"A.M. de Jong" <ar****@wxs.n l> wrote in message
news:bo******** **@reader08.wxs .nl...
Reading a lot about Nulls right now I still can't find a Technical reason to use it or not.

For what I've understand is this:

In an Ingres database a Null column has a standard extra storage of 2 Bits. In a SQL Server database every column has a NULL-bit telling about this
column it is NULL or NOT.
That means that a varchar-empty NULLABLE column takes no space at all since the Nullable column defines it as NULL.
In that respect: When a lot of varchar columns tend to be empty from the
space point of view make it NULLABLE.

A varchar not nullable column must be filled with a '' when it's empty. That single quote takes 3 bits since a varchar has an overhead of 2 positions.

I am not talking about key-values although sometimes you see
reference-columns to a Master table wich is emtpy (NULL in my case)
Since the master table had no NULL-key item there is no Inner join facility. I don't think SQL likes the outer join that much so it's clear to create an UNKNOWN reference to the master table.
(And place this Unknown item in the master table as well).

But the rest: When should I use nulls and when do I do not ???

Arno de Jong, The Netherlands.


Use NULLs when your data model requires it - that's much more important than
the physical storage requirements (at least for most people). In general, if
the column is an optional attribute, then use NULL; if the attribute is
optional but there is a sensible default available, use NOT NULL with a
DEFAULT constraint; if the attribute is not optional, it should be NOT NULL.

For more information, you might want to search for newsgroup postings by Joe
Celko, and his book "SQL for Smarties" discusses NULLability in some detail.

If you have a specific implementation issue related to NULL/NOT NULL,
perhaps you could give more details (including table DDL), and someone may
be able to point you in the right direction.

Simon
Jul 20 '05 #2
If you looking for logical correctness & practicality of using NULLs in
relational databases, then I would recommend you to go through Date's
Relational Database Writing 89-91 & 91-94 for an excellent treatment on the
issue. It is a very crucial & practical yet widely misunderstood concept and
usage of NULLs have been ingrained to our thought process by SQL databases.
Though Simon has suggested Joe Celko's book, I am a bit skeptical of the
suggestions in his book about using them, being biased based on SQL's flawed
approach to n-VL.

However, if you are just concerned with implementing a SQL table with or
without NULLs, with little concern over precise modeling practices, simply
read though the vendor manual. Nulls, irrespective of how often
characterized as markers for unknown/inapplicable values, are treated like a
"value" in most vendor DBMSs.

--
-- Anith
( Please reply to newsgroups only )
Jul 20 '05 #3
Quit worrying about the storage used by various products; they will make
more and chepaer storage for you. The real question is how to use them
in a data model. My heuristics are:

1) Avoid them if you can. Use a dummy value and put it into a DEFAULT
clause, if the domain of your column needs it.

2) If you have a NULL, make usre it has one and only one meaning in that
domain. Example: The ICD codes for disease use 000.000 for
"Undiagnose d" and 999.999 for "Diagnosed, and we don't know what it is"
for two kinds of missing data.

3) Make sure the propagation property of NULLs makes sense in your data
model. Otherwise, use COALESCE() to replace it with another value.

4) Remember that you must use "CAST (NULL AS <datatype>)" in places
where the compiler needs to know the datatype of a column or variable.

--CELKO--
=============== ============
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
25768
by: Dmitry D | last post by:
Hi, I'm new to C++ (started learning in the beginning of this summer), and I have the following question (sorry if it sounds stupid): In many code samples and source files, I see NULL expression being used (for example, int* someInt=NULL; ). I used similar initialization myself, and it works fine even if I don't define NULL. But what is "NULL" exactly? Is it a constant defined by compiler? Is there any difference between the following two...
4
2806
by: Asif | last post by:
Hi there, I have been trying to understand the behaviour of char (*pfn)(null) for a couple of days. can some body help me understand the behaviour of char (*pfn)(null) in Visual C++ environment? The question is why this is legal char *ptr; char (*pfn)(null); ptr = pfn
0
2974
by: Ben Margolin | last post by:
I am new to subselects, and what I really want is to do them in an update, but the following shows a simpler select, that also doesn't seem to work as I think it should. Advice? Do I just misunderstand how subselects are actually executed? (This is on mysql version 4.1.0-alpha-max-nt.) First, here's the tables in question: mysql> describe m;
2
3652
by: Oleg | last post by:
I am trying to send one of the parameters of stored procedure having a null value. The parameter is of type blob. I declare it in code like 'new OleDbParameter ("p_sigPicture", OleDbType.LongVarBinary)'. The result of execution is exception: 'Stored Procedure is not found'. I don't want to make another stored procedure for the case when the is no parameter to pass. What can I do to pass a null value?
30
2251
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL; return NULL; }
66
3067
by: Mantorok Redgormor | last post by:
#include <stdio.h> struct foo { int example; struct bar *ptr; }; int main(void) { struct foo baz; baz.ptr = NULL; /* Undefined behavior? */ return 0;
1
2839
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because essentially my worker thread updates the UI, which is BAD. So, here I am trying to figure out how...
17
4534
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are selected into 2 different SP variables and compared for equal. They are both NULL, but do not compare as equal. When the Not NULL columns (SALARY) are compared, they do compare as equal.
10
1400
by: Jeff | last post by:
I guess that I should have explained better (I'm stil new with this, so I may not be asking the questions in the best way) Normally, one would use the simple code: if x>y then something end if
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.