473,651 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2473

"Randall Parker" <NOtechieSPAMpu ndit_please@fut ure_avoidjunk_p undit.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" <NOtechieSPAMpu ndit_please@fut ure_avoidjunk_p undit.com>
wrote in message news:OT******** ******@TK2MSFTN GP12.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" <NOtechieSPAMpu ndit_please@fut ure_avoidjunk_p undit.com> a
écrit dans le message de news: %2************* ***@TK2MSFTNGP1 2.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
8775
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 (i.e. a zero length string). We are using SQLBindParameter() to bind a variable to the parameterized insert statement <<in the form: INSERT INTO table VALUES (?, ?, ?)>>. We are using SQLExecDirect() to process the SQL. We are running into the...
7
5541
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 and nulls. In a simple table with first, middle and last name columns, I would infer that a null value in the middle name column means the HR person forgot to ask. A zero length string, however, tells me HR did ask and there is no middle name....
16
2388
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); .......................(1)
3
5880
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 _strVal = "" thanks for enlightening me on this.
1
1049
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
6229
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 work is to make all the index' fields required fields and set the allow nulls setting to false. But then every field in the index should always have some kind of value, and I have to put a default value like "0" in them or "empty". Is this indeed the...
23
7395
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
4
2122
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, there are a few records that are empty. I do not specifically know whether they are "alt + 0160" character.
3
12283
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) length string, an empty Field, or no value at all - so exactly what is Null? The purpose of this Topic is hopefully to explain what a Null Value is, discuss some peculiarities about Nulls, show how we can detect them, and finally, how to convert...
0
8792
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...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
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...
0
7294
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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
5605
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();...
1
2696
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
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.