views:

45

answers:

3

I know storing multiple values in a column. Not a good idea.

It violates first normal form --- which states NO multi valued attributes. Normalize period...

I am using SQL Server 2005

I have a table that require to store lower limit and uppper limit for a measurement, think of it as a minimum and maximum speed limit... only problem is only 2 % out of hundread i need upper limit. I will only have data for lower limit.

I was thinking to store both values in a column (Sparse column introduces in 2008 so not for me)

Is there a way...? Not sure about XML..

+2  A: 

You'd have to be storing an insane amount of rows for this to even matter. The price of a 1 terabyte disk is now 60 dollars!

Two floats use up 8 bytes; an XML string will use a multiple of that just to store one float. So even though XML would store only one instead of two columns, it would still consume more space.

Just use a nullable column.

Andomar
Multiply by your RAID configuration. And how much does the hardware to host that 1TB cost? In such a way that all the people (perhaps 1M internet users) have continuous and concurrent access to it? And the people to support that hardware? Power supply? Disaster planning, on the off-chance your company will DIE if you lose that data?Hard drive space is cheap. Enterprise-level hard drive space is not.
Philip Kelley
@Philip Kelley: What you list can cost (a lot of) money, but it's hardly related to hard disk size. A power supply costs as much for a 1GB disk as for a 1TB disk
Andomar
+2  A: 

To answer your question, you could store it as a string with a particular format that you know how to parse (e.g. "low:high").

But ... this is really not a good idea.

Dealing with 98% of the rows having NULL value for upper limit is totally fine IMHO. Keep it clean, and you won't regret it later.

Tim Drisdelle
+1  A: 

Even so, I agree with Andomar. Use two colums, low limit and high limit. If either value could be unknown, make those columns nullable.

Alternatively, designate a default arbitrary minimum and maximum values, and use those values instead of nulls. (Doing this means you never have to mess with trinary logic, e.g. having to wrap everything with ISNULL or COALESCE.)

Once you define your schema, there are tricks you can use to reduce storage space (such as compression and sparce columns).

Philip Kelley