Solved

A table with a filed nvarchar(50) – how to minimize the resourses for customers that use this filed with NULL value ?

Posted on 2014-01-06
7
311 Views
Last Modified: 2014-01-07
Dear experts,

 I’m using SQL Server 2008, may be will go to 2012 in near future and I have a question.

I have a table with 10 filleds, that will go to some millions records. In that table I should add a nvarchar(50) which will be used only for some customers, for others this Keyword nvarchar(50) filed will be empty.

 So my question is – for the customers that will NOT use at all this Keyword field, this will increase the size of DB or not?  What exactly type I should use and at all, what should I do to minimize the recourses used for the customer with Keywords = null ??? I prefer not to make different logic …
0
Comment
Question by:dvplayltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39761433
there shall be no increase for the existing rows.
for NULLable fields, if the field value IS null, a single "bit" in the data will indicate the field value is null. for existing records, this will not change any data, as that bismask will be in a existing byte for the already existing columns.

for the rest, you data type is ok, you should only make sure that the field accepts NULL (is nullable) which is usually the default
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39761444
In such cases I'd recommend putting this extra field into a "detail" table which is in 1:1 relationship with the "master" table. Joins with appropriate indexing should be piece of cake; the only tradeoff would be creating a unique index on the master table if doesn't exist yet but I assume it does for a table with millions of rows.
0
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 39761448
1. You can use isnull(column1,'') to select also those records having null value on this column;
2. Use Insert/Update triggers to enforce that the users have to put values on it, if you want to have value on it

Yes, correct database size is depending on whether there are values on the columns or not.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Author Closing Comment

by:dvplayltd
ID: 39761518
10x for your answer. One more clarify - if I set the value to empty string - this is the same as set to NULL or not ?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39761522
in sql server, empty string is NOT the same as NULL
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39761583
I think dvplayltd's question is about space usage; i.e. does an empty string occupy more space than a null in case of an nvarchar50 field? My gut feeling says yes, empty string must occupy more space, but I'm not familiar enough with SQL Server 20xx to tell for sure.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39761686
yes, it does. because NULL will only be 1 bit in the "null bitmask", while empty string will have the information of how long the string actually is in a "header" byte/double-byte.
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question