Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
>What is the easiest way to make column unique?
>
>I created a unique index on the field but I really dont need the index, so the overhead of the managing the index seems excessive. Is there any other way to make a column unique? Im thinking some sort of check constraint that does a select but I get an error every time I use a query in a check constraint.
>
>Any ideas?
>
>Eric
From the BOL:
"SQL Server automatically creates a UNIQUE index to enforce the uniqueness requirement of the UNIQUE constraint. Therefore, if an attempt to insert a duplicate row is made, SQL Server returns an error message that says the UNIQUE constraint has been violated and does not add the row to the table. Unless a clustered index is explicitly specified, a unique, nonclustered index is created by default to enforce the UNIQUE constraint."
You complain about overhead... but, whould you rather have SQL Scan the whole table each time you add/update a record to make sure the value is unique?
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement