Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Null vs. Zero for Primary Key
Message
De
20/01/2011 12:52:18
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01496573
Message ID:
01496708
Vues:
59
>We are just trying to decide whether a record that lacks a foreign key should have the key listed as 0 or NULL. I think that 0 is easier to work with. For example, if we want to exclude records with a certain two foreign keys or no foreign key, we would say:
>
>SELECT * FROM Table1 WHERE NOT INLIST(Foreign_Key, 13, 32, 0)
>
>as opposed to
>
>SELECT * FROM Table1 WHERE NOT INLIST(Foreign_Key, 13, 32) AND Foreign_Key IS NOT NULL
>
>
>Jerry

Or a left join to the other table with a where clause. Are you really going to know the surrogate int key of the joined table anyway?

I'm with Sergey - for FKs null is the appropriate value.


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform