473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

NULL, zero length strings, and empty controls

I am designing a database schema. It happens to be in MySQL but I'm trying to keep it
portable to other databases should the project grow.

Anyway, suppose you have VARCHAR fields and will be using ASP.Net and ADO.Net. In
your experience does it make more sense to allow NULL values for VARCHAR fields or
will they behave well and get set to zero length strings when a user doesn't fill in
a text field?

I'm wondering if I should do:

myfield VARCHAR(200) DEFAULT NULL,

or
myfield VARCHAR(200) NOT NULL DEFAULT "",

I'd rather do the latter. NULL is just one more thing to check for and I'd rather
just check for a zero length string when I'm reading stuff out of the database.

Anyone find the best practice here differs depending on the database chosen or the
front-end layers being used to build on it?
Nov 19 '05 #1
4 2460

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com> a
écrit dans le message de news: OT**************@TK2MSFTNGP12.phx.gbl...
I am designing a database schema. It happens to be in MySQL but I'm trying
to keep it portable to other databases should the project grow. .... myfield VARCHAR(200) NOT NULL DEFAULT "",

I'd rather do the latter. NULL is just one more thing to check for and I'd
rather just check for a zero length string when I'm reading stuff out of
the database.

Anyone find the best practice here differs depending on the database
chosen or the front-end layers being used to build on it?


treat '' as null depends on the brand, the version and the installation
setup, or even the session options...

Some databases treat '' as null under the default settings (many half
competent admins won't change the default settings if their life depends on
it), some front end layers will treat '' as null even if the database is
able to make the difference, some databases set this at installation.

So the real question is : have you any CONTROL on the database brand or
setup ? Are you dependent on a database administrator ? Are you hosted ?

Nov 19 '05 #2
Michel de Becdelièvre wrote:
treat '' as null depends on the brand, the version and the installation
setup, or even the session options...
I guess I need to figure out what MySQL does with zero length strings on an insert.
Some databases treat '' as null under the default settings (many half
competent admins won't change the default settings if their life depends on
it), some front end layers will treat '' as null even if the database is
able to make the difference, some databases set this at installation.
Well, I'm working on a development database. But I have to get my tables added to an
existing production database.

So the real question is : have you any CONTROL on the database brand or
setup ? Are you dependent on a database administrator ? Are you hosted ?


I know the database administrator. I can't change the database brand they use, at
least not quickly.
Nov 19 '05 #3
null really means value unknow. if you are going to treat nulls as a empty
strings, then you should not use null, but default to ''. in most databases
this actually takes less space (supporting null values generally requires an
extra bit.)

-- bruce (sqlwork.com)

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:OT**************@TK2MSFTNGP12.phx.gbl...
I am designing a database schema. It happens to be in MySQL but I'm trying
to keep it portable to other databases should the project grow.

Anyway, suppose you have VARCHAR fields and will be using ASP.Net and
ADO.Net. In your experience does it make more sense to allow NULL values
for VARCHAR fields or will they behave well and get set to zero length
strings when a user doesn't fill in a text field?

I'm wondering if I should do:

myfield VARCHAR(200) DEFAULT NULL,

or
myfield VARCHAR(200) NOT NULL DEFAULT "",

I'd rather do the latter. NULL is just one more thing to check for and I'd
rather just check for a zero length string when I'm reading stuff out of
the database.

Anyone find the best practice here differs depending on the database
chosen or the front-end layers being used to build on it?

Nov 19 '05 #4

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com> a
écrit dans le message de news: %2****************@TK2MSFTNGP12.phx.gbl...
Michel de Becdelièvre wrote:


So the real question is : have you any CONTROL on the database brand
or setup ? Are you dependent on a database administrator ? Are you hosted
?


I know the database administrator. I can't change the database brand they
use, at least not quickly.


As far as I know :
- Oracle always treat '' as null
- SqlServer as an option, on the driver side (if I remember well I have
not used it in a looong time).

try this link (if anyone knows of similarly usefull links, I'm interested) :
http://troels.arvin.dk/db/rdbms/

Nov 19 '05 #5

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

Similar topics

2
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty...
7
by: BlueDragon | last post by:
I don't know enough math to demonstrate that any numerical operation with a null should yield a null; although I would guess that it's true. I just don't buy it, however, when dealing with strings...
16
by: mike79 | last post by:
Hi all, I have a the following simple piece of code which has taken me hours to try and sort out the problem, but still unable to find what is wrong. void main( void ) { char (*string);...
3
by: Asha | last post by:
greetings, i have some questions below, what are the differences between private string _strVal = string.Empty; and _strVal = null; does the string.Empty; allocate memory for it? how about...
1
by: Randall Parker | last post by:
In places where ASP.Net does the handling of controls for you does it treat controls as null or as zero length strings?
6
by: john | last post by:
Last week I posted about making a unique index on multiple fields to prevent importing identical records twice. I still have trouble with the nulls in the index. The only way that I can make it...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: Eric Layman | last post by:
Hi everyone, Im puzzled by a NULL behaviour in SQL 2000 server. There is a column in the table that does not allow NULL. During data mining, the staff noted that, for that particular column,...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.