nULL OR nOT?
-
The correct answer is that, usually, it doesn't really matter that much. For the properties of some entities it is necessary to distinguish between 'unset' and the default value. This can be achieved with a nullable data type/field or by using some sentinel value. The selection of that sentinel value is easy to select in some cases and difficult in others. In some systems using a well chosen sentinel value that is within the range of the data type used can save a lot of space because it doesnt require another bool to indicate null/non null. In others, and I would argue that almost any database would fall into this category, using an existing facility (dot net's Nullable<> or a nullable database field) is preferable as you can reasonably expect others familiar with the product / technology to instantly understand what it is and why it's there.
_Josh_ wrote:
In some systems using a well chosen sentinel value that is within the range of the data type used can save a lot of space because it doesnt require another bool to indicate null/non null.
Perhaps, but it would require there are no other impacts on the system. For example that non-null fields do not always require space in the paged record and that indexes are not impacted in the same way. And it is only applicable for a table where there is a LOT of data. And thus it would be an optimization for one table requiring it for all tables is pointless.
-
_Maxxx_ wrote:
It would remedy it perfectly. In your example I think you are suggesting that the database wold have a table containing just the sale price, while another table would hold details of the sold item (or, actually, the item Id) and the sale to which it belongs, etc.
As the sale price is an intrinsic part of the line item in most cases I'd suggest that the 'invoice line' table would include the sale price as a column, and would not hold a reference to another table.Actually, I was taking a larger view of the issue than what you've stated here. An item could be sold, but it could also be donated, destroyed, lost, transferred, or disassembled into parts. My other table would be expressing how the item was 'released', means by which it was 'released' and other details. The item could be sold for a negative value, perhaps part of a package deal. NULL indicating 'not sold' seems rather limiting. Additionally, 'price' in my sphere may include two different amounts, two different payment methods, and perhaps two different payees which are summed to get the final total price. I'd have a table of 'transactions' that make up the 'sold price' and so 'sold price' wouldn't be on that item table. A fundamental rule of database design is that fields aren't overloaded with multiple meanings. When NULL for sale price means there is no sale price that is fine. When NULL for sale price means the item hasn't been sold that is a bad thing.
_Maxxx_ wrote:
Again, you're asking UI questions - this shouldn't change our data design.
I'm using the UI to illustrate a point about the data design. If NULL is going to mean something then that needs to be expressed to the users via the UI. If the users don't care about the academic difference between 'never had a value' and 'currently has no value' then I have to wonder if the database design is being made to conform to a textbook or if it's being designed to meet the user's needs.
_Maxxx_ wrote:
That's a business decision - can an address be deleted once it's added? Again, no effect on data design
I pointed out the issues that NULL can raise in the UI to illustrate that decisions made in the database design impact the application throughout and if NULL is going to mean a specific thing on a field then the developer has to have a way to communicate that to the use
MehGerbil wrote:
An item could be sold, but it could also be donated, destroyed, lost, transferred, or disassembled into parts.
I see what you're getting at - and I completely agree - it depends on requirements.
MehGerbil wrote:
When NULL for sale price means there is no sale price that is fine.
When NULL for sale price means the item hasn't been sold that is a bad thing.In the example I was thinking of, which was auction based, there is a 'reason not sold' which could be passed-in, destroyed etc. But there is no status for 'not sold because it hasn't been offered yet' - and a record was created in the Db with a sale price of zero and (effectively) a status of 'sold' and, in fact, a BuyerId of 0 (and a buyer record pre-exists with an Id of zero). So, as you can gather, the design sucks out of the box!
MehGerbil wrote:
I'm using the UI to illustrate a point about the data design.
If NULL is going to mean something then that needs to be expressed to the users via the UI.Again - I see what you mean. And agree. In the case above, having a Null buyer Id is more meaningful (IMHO) to show there is no buyer than having a buyer record with a description of something like 'No Buyer'. And, assuming there's no buyer, there is no sale price so it should be null and not zero. So Null isn't really representing anything other than the lack of a sale price - while the Null buyer shows there is no buyer. I guess my gripe is that people seem to sometimes avoid using Nulls because of their laziness (they can't be bothered to differentiate client-side so add a record representing no buyer, or whatever, to simplify their SQL - but really they end up with code that tests for magic Ids instead of Null.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
The databases in question used VB6 for the front-end? (Zero is common for extremely low values of null in VB6). Primary reason that I don't like to use 0 for a key value and start from one, don't want to break anything. Now, as far as not null goes, I prefer the fourth normal form in cases you have described. I will leave the understanding as an exercise for the reader.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost "All users always want Excel" --Ennis Lynch
Ennis Ray Lynch, Jr. wrote:
The databases in question used VB6 for the front-end?
Interestingly in this case the OLD platform was VB6 - and teh new Db was designed by those old VB programmers - so you're right, that could well be the reason.
Ennis Ray Lynch, Jr. wrote:
I prefer the fourth normal form in cases you have described
our database is, unfortunately, not normal in any way ;) It falls short of 3NF in many areas already!
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
_Maxxx_ wrote:
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database.
So at best they are ignorant.
_Maxxx_ wrote:
The argument I get is that "the customer does have an address, but we just don't know what it is yet."
The database is a persistent store - not a god. It "models" the data objects. And obviously if they want "We don't know what it is" then that is exactly what they should put in the database.
_Maxxx_ wrote:
but am willing to change my view if anyone can give a sound reason for any of this garbage.
One reason of course is that they do not in fact understand what null is. It confuses them. So a "sound" reason would be that you don't want to confuse them.
jschell wrote:
One reason of course is that they do not in fact understand what null is. It confuses them. So a "sound" reason would be that you don't want to confuse them.
NOOOOOooooo! That is certainly not a sound reason for using bad practices - it is sound reason for education!
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
I like nulls; I don't like "magic values". Disallowing nulls is not a solution to the problem.
-
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
Is it possible they have simply read or heard that nulls are bad and so eradicate them with defaut values without understanding the database principles behind the statement? (I regularly use nulls in database design, normalising every last one away is rarely a worth it). Greg
-
d@nish wrote:
So, when exactly should I drink coffee?
At 8:50 - just before your scrum meeting. (I generally drink more tea than coffee just to reduce my caffeine and calorie intake - I drink earl gray tea, black nothing added) You do have a scrum meeting with yourself, don't you?
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
Darjeeling, black, then attend to correspondence. The coffee comes mid morning when the code starts happening. Lucky enough to have an espresso machine at the office, so it's usually a cappuccino for me :cool:
-- For a moment, nothing happened. Then, after a second or so, nothing continued to happen --
-
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
Yes, your example is FUD tactic for wrong practice. NULL is standard, my counter questions for those programmers is: "How do you handle three state logic and do you enforce "standards of yours" across all of your projects?"
Mislim, dakle jeo sam.
-
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
The main reason for doing this, especially on FK's, is that you don't have to worry about what kind of join you're doing. If you have nulls, you need to usually use an outer join rather than a full join or an inner join. Otherwise, it's sort of a semantic difference to use 0 instead of a null, but that can also be really dangerous. Null means something which is different from zero, or any other value.
_Maxxx_ wrote:
but am willing to change my view if anyone can give a sound reason for any of this garbage.
My reason regarding the joins should be moot - any decent SQL generator should know to use the correct join when dealing with nullable FK's. On the other hand, people are lazy. Not a good enough reason to adopt their policies, IMO. Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My Blog -
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
NULL is not indexed use NULL in arithmetic, string, logical and others operations is incorrect its use is the result of a incorrect designing database.
-
I am against using nulls in the database because it means introducing 3 valued logic, which is known to be bad. The behavior of SELECT and conditions when nulls are involved is too complicated.
Rosenne wrote:
it means introducing 3 valued logic, which is known to be bad.
Known by whom? If there are three logical values then you need to use 3 valued logic!
Rosenne wrote:
The behavior of SELECT and conditions when nulls are involved is too complicated.
Because you don't understand it is not a good reason for not using it - it simply means you should not be designing databases.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
NULL is not indexed use NULL in arithmetic, string, logical and others operations is incorrect its use is the result of a incorrect designing database.
Igor Kovalev wrote:
NULL is not indexed
In which database? My understanding is that oracle while not actually indexing nulls, will still utilise an index on a nullable column. And I think SQL Server does index nulls.
Igor Kovalev wrote:
use NULL in arithmetic, string, logical and others operations is incorrect
Interesting statement? says who? Incorrect why, in what way?
Igor Kovalev wrote:
its use is the result of a incorrect designing database.
so. pray tell, why do databases even HAVE a NULL? If it's so incorrect to use it, surely databases sholdn't support it?
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
Igor Kovalev wrote:
NULL is not indexed
In which database? My understanding is that oracle while not actually indexing nulls, will still utilise an index on a nullable column. And I think SQL Server does index nulls.
Igor Kovalev wrote:
use NULL in arithmetic, string, logical and others operations is incorrect
Interesting statement? says who? Incorrect why, in what way?
Igor Kovalev wrote:
its use is the result of a incorrect designing database.
so. pray tell, why do databases even HAVE a NULL? If it's so incorrect to use it, surely databases sholdn't support it?
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
1)SELECT on the table that has a value of NULL will result in FULL SCAN 2)try null = null or null + 4 3)look for database normalization
-
_Maxxx_ wrote:
The argument I get is that "the customer does have an address, but we just don't know what it is yet."
Which is actually correct, and quite a nice way of stating a technical point in plain language. The empty string represents an unset address, whereas null indicates that there is no address. Unsurprisingly, most people don't think "does a field have a value or not?", they think "do we know the address?". Only developers are brought up to detach data from reality, and DBAs don't have to be developers, but they do have to know their data.
I wanna be a eunuchs developer! Pass me a bread knife!
There is something inherently wrong with a product that has not been assigned a price being defaulted to zero. I actually had a customer order his "free" device because it showed up in the catalog with a price of zero. If it were null, it would have missed the query. Some fields should allow null, some must allow null and yet others must not.
-
1)SELECT on the table that has a value of NULL will result in FULL SCAN 2)try null = null or null + 4 3)look for database normalization
1. Not true - check your facts. 2. Sorry - I see what you mean - yes, certainly it is incorrect to try to do arithmetic on 'nothing' so, let's say you have a numeric column on your table and, instead of using null to represent it not having a value, you use zero. Now, what is the average of that column? You can't tell which rows to count because you are not differentiating between rows who's value is zero and rows that do not have a value. 3. Mate, I've been doing database normalisation longer than you've been alive; if you have a point to make, make it! you said "its use is the result of a incorrect designing database." So you are saying you should not design a database to have null columns? Unless I am misunderstanding what you are saying, then you imply that the NULL 'value' is not necessary!
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
1. Not true - check your facts. 2. Sorry - I see what you mean - yes, certainly it is incorrect to try to do arithmetic on 'nothing' so, let's say you have a numeric column on your table and, instead of using null to represent it not having a value, you use zero. Now, what is the average of that column? You can't tell which rows to count because you are not differentiating between rows who's value is zero and rows that do not have a value. 3. Mate, I've been doing database normalisation longer than you've been alive; if you have a point to make, make it! you said "its use is the result of a incorrect designing database." So you are saying you should not design a database to have null columns? Unless I am misunderstanding what you are saying, then you imply that the NULL 'value' is not necessary!
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
I ve been doing database normalisation longer than you've been alive;" why you discuss about this issue with me? The use of NULL is true for Oratsle but not true for all DB. In another DB empty string is it not NULL
-
I ve been doing database normalisation longer than you've been alive;" why you discuss about this issue with me? The use of NULL is true for Oratsle but not true for all DB. In another DB empty string is it not NULL
Igor Kovalev wrote:
why you discuss about this issue with me?
Because you are stating as facts things that are not true, and you are responding to my initial question about the use of nulls
Igor Kovalev wrote:
The use of NULL is true for Oratsle but not true for all DB.
Oracle I assume you mean? And you mean that Nulls are not indexed in Oracle? Yes, I understand that that is true. I also understand it is not true for all databases.
Igor Kovalev wrote:
In another DB empty string is it not NULL
sorry, I don't understand? Appreciate English probably is your 2nd language; I don't believe in any database an empty string is null. Null has a special meaning - i.e. 'there is no value'
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
Igor Kovalev wrote:
why you discuss about this issue with me?
Because you are stating as facts things that are not true, and you are responding to my initial question about the use of nulls
Igor Kovalev wrote:
The use of NULL is true for Oratsle but not true for all DB.
Oracle I assume you mean? And you mean that Nulls are not indexed in Oracle? Yes, I understand that that is true. I also understand it is not true for all databases.
Igor Kovalev wrote:
In another DB empty string is it not NULL
sorry, I don't understand? Appreciate English probably is your 2nd language; I don't believe in any database an empty string is null. Null has a special meaning - i.e. 'there is no value'
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
yes it's my secondary language.
I am sorry for the misuse. about equals empty string and null...
https://db.apache.org/torque/torque-3.3/version-specific/database-howtos/oracle-howto.html
you'll be surprised -
I've come across a practice in more than one company where one or more develpers insit on not using null values in the database. So, for example, if a customer address is unknown, the AddressId on the Customer table will have a value of (for example) zero - and the Address table will be pre-populated with a record with an Id of zero and (usually) empty string or zero values in the other columns. I've also come across the situation where, rather than having a null value in a 'sold price' column, the value of zero represents an unsold item. Putting aside my feelings (that these are weak-minded imbeciles who shouldn't be allowed near a database) do any of you subscribe to this theory? What's wrong with a null value which tells you explicitly "The customer has no address" or "This item has no price" The argument I get is that "the customer does have an address, but we just don't know what it is yet." I put it down to FUD factors - but am willing to change my view if anyone can give a sound reason for any of this garbage.
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
RIGHT, sounds like some very old DBA's whose time is before Null became popular/sensible. An address, espicially if it is the first record, should not allow null; a person can have more than one address, so let the second/third,etc. allow nulls. Yes, I am having my tea. The front end issues can be resolved by checking for nulls in the stored proc CRUD's and sending error messages out instead of garbage; avoiding lot's of metadata on what the default values should be; today a zero, tomorrow an empty string. I use Null in all of my query's/procs, it is a must for any DBA or Programmer; consistancy that everyone can agree on. As long as your using it and checking for it, apps won't crash because of unkowns yet to be know and the database won't fill up with garbage, espicially ID's. I struggle all the time with poor app/database design, sigh, guess thats why we get the big bucks. Hang in there and don't let the bastards make you use MS Access, lol. ;)