title: T-SQL: How do I create a unique key that is case sensitive?
body: <p>How do I create a unique constraint on a <code>varchar</code> field that is case sensitive (SQL Server 2005)?</p>
  
  <p>Currently my constraint looks like this:</p>
  
  <pre><code>alter table MyTable
  add constraint UK_MyTable_MyUniqueKey unique nonclustered (MyCol)
  </code></pre>
  
  <p>When I try to insert the following two values, I get a "Violation of UNIQUE KEY constraint..." error.</p>
  
  <pre><code>insert into MyTable (MyCol) values ('ABC')
  insert into MyTable (MyCol) values ('abc') --causes a violation of UNIQUE KEY constraint 'UK_MyTable_MyUnqiueKey'
  </code></pre>
  
  <p>I would like the two differently-cased values to be handled as unqiue. I imagine it will involve the following code, but I do not know how it changes my <code>add constraint</code> syntax.</p>
  
  <pre><code>COLLATE SQL_Latin1_General_CP1_CS_AS
  </code></pre>