Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a varchar(max) column where users will populate a pre-given key from another system. I want to enable that the users are forced to enter a unique key which means no duplicate values on that specific column. Should I change the collation or is there some sort of check constraint that I can add?

share|improve this question
People are entering > 900 bytes by hand? This does not sound like a "key" to me... – Aaron Bertrand Feb 25 '13 at 2:18
up vote 4 down vote accepted

Ordinarily, you'd just create a unique constraint on that column. But you can't put a unique constraint on a varchar(max) column. That could be close to 2GB per index entry.

In SQL Server, the maximum size of an index key is 900 bytes. I believe SQL Server enforces unique constraints by using a unique index, so I'd expect that limitation to apply to your problem, too.

In any case, I think this is an XY problem.

share|improve this answer
I don't think you can have a unique constraint on a varchar(max). It's up to VARCHAR(8000). – ypercubeᵀᴹ Feb 24 '13 at 13:44
@ypercube: Yeah, I realized it was a varchar(max) column right after I posted, and I was looking for the limits. Thanks. – Mike Sherrill 'Cat Recall' Feb 24 '13 at 13:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.