Unix Technical Forum

PK

This is a discussion on PK within the SQL Server forums, part of the Microsoft SQL Server category; --> I have seen some look-up tables have no primary key because there is a null or " " value ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:38 PM
J
 
Posts: n/a
Default 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".



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:38 PM
yangyang
 
Posts: n/a
Default Re: PK

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 06:38 PM
David Portas
 
Posts: n/a
Default Re: PK

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/m...S,SQL.90).aspx
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 06:39 PM
Mark D Powell
 
Posts: n/a
Default Re: PK

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 --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:17 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com