Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to detect if a record is repeated
Message
De
29/08/2006 18:41:31
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., Nouvelle Zélande
 
 
À
29/08/2006 18:17:32
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01149577
Message ID:
01149581
Vues:
7
You want to know whether a field value is unique?

SQL Server forces uniqueness if you make the field a primary or candidate key or if you use a unique constraint. There are lots of opinions, but you are probably better not to use a human-entered field for a primary key. A unique constraint makes your intent immediately obvious, and a table can have more than one unique constraint as opposed to a single primary key. All of these techniques mean that if a value is saved that already exists in a different record, the record will not save and you can catch the resulting error.

However, IMHO it is better to check uniqueness as soon as the user enters the value- you can imagine the annoyance if a user enters lots of customer details and tries to save before discovering the customer is already there. You could use a SPT or SP to check for the value and let the user decide whether to pull up the existing details or choose a different value. There is still a chance that 2 users might start adding the same details at the same time, but users aren't as quick to blame the software if that happens.
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform