开发者

unique constraint on large text field

I have a table with a column for xml feed entry as (nvarchar(max)) and executed a hash function (Md5) on this column to get a hash key to aid in searching and also maintain uniqueness. It is typically over 900 bytes long.Now I have realized that the hash key does not guarantee uniqueness since I just did a coun开发者_如何学编程t of duplicate rows on that column and was amazed and when I tried to create a unique index on the hash key column itself, SQL SERVER gave me an error of cannot create unique index on non deterministic column..something like that.

Now I have searched and found that in some cases I should use the type (ntext) and create a unique index on that; others mention using checksum and an index on that, whilst others mention triggers, checksum, etc. Which would be the best method to implement on this field for uniqueness keeping in mind that the table already has 22 million records and I cannot afford to lose any data. Thanks in advance


Microsoft recommends not using ntext types because they will be deprecated in the future. Documentation is here. So I would go with using checksums and putting the unique index on that. This post discusses this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜