Why can’t I put a constraint on nvarchar(max)===nvarchar(max)类型为何不能做约束?

来源:互联网 发布:淘宝c店如何推广 编辑:程序博客网 时间:2024/06/08 16:26

Why can’t I put a constraint on nvarchar(max)?

 

 

 

nvarchar(max) is really a different data type from nvarchar(integer-length).

It's characteristics are more like the deprecated text data type.

If nvarchar(max) value becomes too large, like text, it will be stored outside the row (a row is constrained to 8000 bytes maximum) and a pointer to it is stored in the row itself.

You cannot efficiently index such a large field and the fact that data can be stored somewhere else further complicates searching and scanning the index.
A unique constraint requires an index to be enforced and as a result, SQL Server designers decided to disallow creating a unique constraint on it.