Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Null vs. Zero for Primary Key
Message
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01496573
Message ID:
01496713
Vues:
56
Hi Jerry,

The NULL is appropriate. You can use SQL Server RI for FKs with NULLs.
Re-read your description for the query and you'll see that you stated 2 conditions: 'exclude records with a certain two foreign keys or no foreign key'. The second query mirrors your requirement.
SELECT * FROM Table1 WHERE Foreign_Key NOT IN(13, 32) AND Foreign_Key IS NOT NULL
>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
>
>
>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform