Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Difference default = '' or default = NULL?

Author  Topic 

neutcomp
Posting Yak Master

111 Posts

Posted - 2004-02-05 : 09:55:03
Yep thats the question:

Is there a difference between
userId tinyint(3) default ''

or
userId tinyint(3) default NULL


Thanxx
Bjorn

MuadDBA

628 Posts

Posted - 2004-02-05 : 10:51:01
yeah, one is an ASNI standard and one is not.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-02-05 : 10:57:15
And they would give them different default values.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2004-02-05 : 11:02:34
There is a difference between '' and NULL. NULL is used to indicate that the value is undefined. '' is a zero length string.

quote:

yeah, one is an ASNI standard and one is not.



What is that supposed to mean?

The only thing relating to ANSI is that tinyint is not a standard type.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-02-05 : 11:19:04
For '' it would be implicitely converted to a tinyint and give 0.
null would give null - unless the column didn't allow it in which case it would give an error.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 12:12:03
I did not know that...


DECLARE @x tinyint
SELECT @x = ''
SELECT @x
SELECT @x = NULL
SELECT @x



(....yeah, yeah, so the list is long)



Brett

8-)
Go to Top of Page

neutcomp
Posting Yak Master

111 Posts

Posted - 2004-02-05 : 13:11:35
Oke,

I understand that there is a difference between the two!
Not sure what exactly but there is one :-P

Thanxx
Bjorn
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-02-05 : 14:38:57
It is very important to understand what Null is when dealing with SQL.

what is the difference between 0 and Null?

Null = not sure, not applicable, unknown, undefined, might be 0, might be 1,000,000, might not be calculatable at all (i.e., something divided by 0)

0 = 0, no doubt about it.


- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 14:49:30
NULL is the absence of anything...it is non existance (like the money in my wallet)

Null is not equal to anything, not even itself.

Why?

Because it doesn't exist...

Kinda like a politician and ethics...



Brett

8-)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-02-05 : 19:52:13
No, politicians and ethics both exist, they just cancel each other out when attempting to combine.
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-02-06 : 12:03:46
quote:
Originally posted by X002548

NULL is the absence of anything...it is non existance (like the money in my wallet)



I think you are adding confusion to the discussion. If you are saying that you don't have any money in your wallet, then that is not null. That is actually zero (a value). The only way the money in you wallet could be considered null is if you don't know how much money is in your wallet. Maybe that is what you are saying, but it seems strange for someone to complain about not knowing how much money is in there wallet, unless maybe they lost it or something. See ... I'm getting confused.

neutcomp, I'm curious why you have this question. Is there more?

Jay White
{0}
Go to Top of Page

neutcomp
Posting Yak Master

111 Posts

Posted - 2004-02-06 : 12:07:56
quote:
Originally posted by Page47

quote:
Originally posted by X002548

NULL is the absence of anything...it is non existance (like the money in my wallet)



I think you are adding confusion to the discussion. If you are saying that you don't have any money in your wallet, then that is not null. That is actually zero (a value). The only way the money in you wallet could be considered null is if you don't know how much money is in your wallet. Maybe that is what you are saying, but it seems strange for someone to complain about not knowing how much money is in there wallet, unless maybe they lost it or something. See ... I'm getting confused.

neutcomp, I'm curious why you have this question. Is there more?

Jay White
{0}



I always have more questions, and the answers are also bringin up new question. I used the '' and NULL in one and the same database and I was wondering if there was a difference so thats why the question popsup!

Cya
Bjorn
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-06 : 12:21:34
Jay,

If there is no money in my wallet, that's null...it's not there, doesn't exist...it's not like the state of a balance in an account...

And it's not predicated on the fact that there may be money in there in the future...

However I see your point, you could say I have 0 dollars...

just my lame attempt at humor...





Brett

8-)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-02-06 : 12:53:34
quote:

If there is no money in my wallet, that's null...it's not there, doesn't exist...it's not like the state of a balance in an account...



no !!! if there is no money, then the amount of money in your wallet = 0. end of story. when you say "i could say 0 dollars", you SHOULD say zero dollars because it IS zero dollars.

how much money in the wallet = 0
how many $20 bills in the wallet = 0
what color is the money in the wallet = NULL (there is no money)
what is the ratio of $20's to $10's in your wallet? NULL (can't divide by zero, undefined)


- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-06 : 13:51:18
quote:
Originally posted by jsmith8858

quote:

If there is no money in my wallet, that's null...it's not there, doesn't exist...it's not like the state of a balance in an account...



no !!! if there is no money, then the amount of money in your wallet = 0. end of story. when you say "i could say 0 dollars", you SHOULD say zero dollars because it IS zero dollars.

how much money in the wallet = 0
how many $20 bills in the wallet = 0
what color is the money in the wallet = NULL (there is no money)
what is the ratio of $20's to $10's in your wallet? NULL (can't divide by zero, undefined)


- Jeff



I respectfully disagree...

Now if I had a $20 and a Bill for $20 I have a total of $0...

If I then go pay that bill, and hand everything over to the merchant, there's nothing left...

Anyway...only 3 hours left here on the east coast...




Brett

8-)
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2004-02-06 : 15:03:43
I would argue that a piece of paper currency that is printed for $0 is having 0 dollars. You would then have a piece of currency, but it's value is 0.

If your wallet is empty, you have NULL dollars. The money is non-existant therefore tis NULL.

But what do I know? I say put all your money in a cursor and see how long it takes to total itself!

Come on 5 o'clock!

Aj
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-02-06 : 15:41:01
NULL means "Missing", "Unknown" or "Not Applicable". When your wallet is empty you have zero dollars. It doesn't matter if you have a zero dollar bill or not.

There are three ways to have NULL dollars in your wallet (from my perspective) ...
1.) I never asked you how many dollars you have in your wallet.
2.) You never told me how many dollars you have in your wallet.
3.) You don't own a wallet, so the question does not pertain to you.

However, if you have a wallet and I ask you about it and you tell me you've got no scratch, then you have zero dollars in your wallet. It is a known value. You should be happy to have NULL dollars in your wallet, cause that means there is a chance you loaded ... you just don't know.

This is getting silly.

"I'm rich, bitch!!" -Chappelle

Jay White
{0}
Go to Top of Page
   

- Advertisement -