June 15, 2011 at 3:35 am
Hi Friends,
I have requirement to add unique constraint on nvarchar(max) i am searching for a solution cant get.
Please share ideas on this
Cheers,
vinoth
June 15, 2011 at 4:16 am
unique contraint will create a key and hence has a limit of 900 byte. you can still create an unique contraint with nvarchar(4000) but chances are your inserts will fail.
checking unique will be need to be done before the insert such as merge statements etc.
else u can use a hashing option such as checksum ( not very reliable ) or hashbytes to generate a smaller value column which can be indexed and constrained.
hastbytes below :-
June 15, 2011 at 4:24 am
maybe this helps:
NEWID ( ) function creates a unique value of type uniqueidentifier.
http://msdn.microsoft.com/en-us/library/ms190348.aspx
Regards,
Iulian
June 15, 2011 at 5:58 am
You could create a hash column as a calculated column next to your varchar(max) and then put a unique constraint on the hash column. It's unlikely to be perfect, but it should get you close.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply