Clustered Constraint?

  • Hello! Just two quick questions.

    From BOL:

    quote:


    Although a unique index will help locate information, for the best performance results it is recommended that you use primary key or unique constraints instead. For more information about these constraints, see Primary Key Constraints and Unique Constraints.


    1) Clustered Unique Constraint or Clustered Unique Index?

    2) Is a unique index (or constraint) slower in performance than a "non-unique" (excuse my English )?? I mean, I always check if there is a record with the same value before I insert into the table anyway. So is there a point in making the column unique?

    Thanks in advance!

    /Tomi

  • In my opinion it is best to get into the habit of enforcing Unique Constraints for primary keys. They do perform better and you protect you table against less thorough users who may not check to see if a value exists. Incidentally you might find it quicker to check for the Error returned by SQLServer when you try to insert a duplicate value into a unique key, rather than do a select check before inserting. This is best achieved by using a stored procedure to perform your insert and checking the value of @@ERROR straight after the insert statement.

    Finally a Clustered index is a speciality, it determines that your table will be sorted by such an index as a default. It also has a storage overhead in that SQLSErver actually stores the values in the Clustered index in a more verbose way than a normal index.

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • Hello and thanks!

    I got an answer to question #2 but not to question #1. Or I got an answer to both questions, I just didn't get it .

    So, should I use a clustered constraint or clustered index? Oh, and the column isn't a PK.

    Thank you!

    /Tomi

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply