Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validate unique entry in a field
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01555897
Message ID:
01555900
Vues:
51
This message has been marked as the solution to the initial question of the thread.
>Hi,
>
>I have a field in a table USER_ID CHR(20) which has to be unique for every record. I thought that if I default the value of this field to Null (make it Nullable) it would solve the problem where no value is assigned by user into this field. But SQL Server considers NULL a valid value and gives me "The duplicate key value is (NULL)". Does it mean that my only option to enforce this rule is in code? (Actually the code is VFP so it is not difficult but I want to know if there is another option).
>TIA.

If you're using SQL Server 2008 and up, you may want to go with the filtered index.

http://aboutsqlserver.com/2010/09/12/sunday-t-sql-tip-uniqueness-of-nullable-field/

http://social.msdn.microsoft.com/Forums/en/transactsql/thread/447b135e-3625-4d81-bacf-35122445256e
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform