473,750 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Null or empty string in a database

Jay
For a column that contains a string (let's say varchar[50]), is there any
performance advantage in not allowing nulls, and using an empty string ("")
to instead?

Sep 27 '07 #1
4 3035
"Jay" <-wrote in message news:OE******** ******@TK2MSFTN GP05.phx.gbl...
For a column that contains a string (let's say varchar[50]), is there any
performance advantage in not allowing nulls, and using an empty string
("")
to instead?
For perfomance, I have no idea. Probably none.

But I must confess I've done a not null on a varchar
- just to make sure I always get a string and not a null from the database.

I work a lot with ASP.NET and sporting a string as a null,
is a no no. It makes your whole webpage goes kaboom.

Enforcing rules on a database just to have your C# easier
is wrong in my opinion. But very safe in .NET 1.1

For .NET 2.0 and above, it is just stupid as you can always do:

string s = MyData[col, row].SomeValue ?? "";

....

As a sidenote, remember the thread on "" and String.Empty?
Here is a good example why "" is sometimes better...

1) string s = MyData[col, row].SomeValue ?? "";
2) string s = MyData[col, row].SomeValue ?? String.Empty;
1) readable, we want SomeValue
2) too verbose, if you read it fast, you might be looking for SomeEmpty
below. *s*

- Michael Starberg



Sep 27 '07 #2
In SQL Server, the is a performance advantage to search for col1 is null
rather than col1 = ''

This is because there is a flag in the row header for each column indicating
whether its null so it is easier to check this flag then do a string
comparison

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Jay" wrote:
For a column that contains a string (let's say varchar[50]), is there any
performance advantage in not allowing nulls, and using an empty string ("")
to instead?

Sep 28 '07 #3
Jay
Thanks Ciaran,

Yes, I see what you mean, although presumably if the column isn't nullable,
SQL Server wouldn't have this flag, so wouldn't need to check it first. I
assume that checking it wastes time for strings that aren't null.

Jay

"Ciaran O''Donnell" <Ci************ @discussions.mi crosoft.comwrot e in
message news:35******** *************** ***********@mic rosoft.com...
In SQL Server, the is a performance advantage to search for col1 is null
rather than col1 = ''

This is because there is a flag in the row header for each column indicating
whether its null so it is easier to check this flag then do a string
comparison

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Jay" wrote:
For a column that contains a string (let's say varchar[50]), is there any
performance advantage in not allowing nulls, and using an empty string
("")
to instead?

Sep 28 '07 #4
Jay wrote:
For a column that contains a string (let's say varchar[50]), is there any
performance advantage in not allowing nulls, and using an empty string ("")
to instead?
In many cases NULL and "" would mean something completely
different.

I would be very reluctant to reduce data reliability for
a performance gain I doubt exist.

Arne
Oct 3 '07 #5

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

Similar topics

19
3452
by: Baldur Norddahl | last post by:
Hi, How come "X=null" is not the same as "X is null"? I got a few selects with queries like this: select * from foo where customer=#customer# or (#customer# is null and customer is null) Without the last part, it will not correctly match null customers.
12
4052
by: AFN | last post by:
I am running the code below to generate XML from a data table. But some fields in the data table are Null for every record. Suppose field5 has a null database value. I would expect to see: <field5></field5> or <field5 /> but instead it doesn't even show the field at all for those records where field5 is Null! Instead it just shows: <field4>Whatever</field4>
3
9572
by: Paul T. Rong | last post by:
Do "" and Null both mean nothing?¡¡ If I don't type anything in text box, the its value is Null£¿¡¡Or it is ¡°¡±£¿ I don¡¯ think they are the same, but I don¡¯t know their difference. Thanks.
8
10409
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
0
2268
by: Dana | last post by:
I am using the XMLTextWriter to build an XML string and pass it to the XMLDocument. When I get the data from SQL Server, some of the values passed to the XML are NULL in the database. When I try and run an update to database using the same XML string, (using SQL parameters to pass the selectsinglenode), the XML always shows the NULL values as an empty string "". This is then updating the database with an empty value rather than keeping...
5
2152
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES ( @client,@dateposted)" Dim objCmd as New SqlCommand(CommandText,objConn) with objCmd.Parameters .Add("@client",SqlDbType.Char,50).value = "the companies next test" .Add("@dateposted",SqlDbType.datetime).value = dateposted.text
3
1237
by: Larry Charlton | last post by:
I'm building an n-Layer application that may be segmented into n-Tiers. For the user interface I'm implementing an MVC architecture. Since I can't access the page class directly from another class, is there a way to put items in the viewstate without writing a function in the aspx page? i.e. I can do the following Public MustInherit Class EditViewBase Inherits System.Web.UI.Page Public MustOverride Property Persist(ByVal key As...
4
2135
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.
2
14659
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
9000
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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
9339
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
8260
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
6804
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
6081
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
4713
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...
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
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.