Link to home
Start Free TrialLog in
Avatar of dvplayltd
dvplayltdFlag for Bulgaria

asked on

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

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 …
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Avatar of dvplayltd

ASKER

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 ?
in sql server, empty string is NOT the same as NULL
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.
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.