Since, guid values will always be unique anyway why use a unique index. Isnt it true that when you use a unique index that it slows down inserts?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Uses of UNIQUE constraints:
Enforcing uniqueness. Although a generated GUID is very likely to be unique, you could easily insert the same GUID in multiple rows. Of course you could do it by mistake, but this may even be part of your design, for instance for compound key constraints in many-to-many tables.
Being the target of a foreign key. You probably are accustomed to FOREIGN KEY referencing a PRIMARY KEY of the parent table. Did you know that a FOREIGN KEY can also reference a UNIQUE KEY?
Performance. UNIQUE is a constraint, as others have pointed out, but in most brands of database, an index is implicit when you define a UNIQUE, PRIMARY KEY, or FOREIGN KEY constraint. You’re right that there’s some overhead when inserting to any indexed table, but the performance benefit of an index is a net win, usually many times over.
Uniqueness notwithstanding NULL. While the primary key is crucial for the use of identifying a rows in a table, they don’t permit NULLs. You can use UNIQUE constraints to enforce uniqueness in nullable columns.