Wednesday, March 7, 2012

PK

I have seen some look-up tables have no primary key because there is a null
or " " value in them. Since every table should have a Primary Key, can
anyone educate me how can I handle null or " " value, in the code level? I
am avoiding using Surrogate key.

Thanks,

J

P.S. Null or " " value is "Unknown".The primary key can not be null,or it can not be a primary key.
Add anther Column to this table to create a primary of this column.|||J wrote:
> I have seen some look-up tables have no primary key because there is a null
> or " " value in them. Since every table should have a Primary Key, can
> anyone educate me how can I handle null or " " value, in the code level? I
> am avoiding using Surrogate key.
>
> Thanks,
> J
>
> P.S. Null or " " value is "Unknown".

Nothing technically wrong with ' ' as a key if that makes sense to your
business. If you have nulls then eliminate them either by decomposition
or by encoding the unknown value as something else. There is no excuse
not to have a candidate key.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--|||J, I suspect that if you have NULL in the colum or a column of what
should be the natural key to a table that you have bad data or a
non-normalized table.

Fixing bad data is usually easier than fixing bad design.

Adding a surrogate key will do nothing to protect the integrity of the
business data in the columns in question.

Good luck
-- Mark D Powell --

No comments:

Post a Comment