Skip to content Skip to sidebar Skip to footer

Varchar(max) Column Not Allowed To Be A Primary Key In Sql Server

Varchar(max) column not allowed to be a Primary Key in SQL Server. What is the max length of a varchar type that can be made a primary key. This might be a bad practice, but came a

Solution 1:

900 bytes is the max length for a primary key, this is a bad idea in my opinion, why don't you use a surrogate key instead?


Solution 2:

This question has already been answered in this thread; the short answer is that an index field cannot exceed 900 bytes. That said, it's generally a bad idea to use a long VARCHAR field as an index for myriad reasons such as efficiency and maintainability.


Solution 3:

The primary key is used in all other indexes to identify rows. Having a potentially multi-megabyte value as a key makes very little sense, hence the limit in general on total bytes in any key.


Post a Comment for "Varchar(max) Column Not Allowed To Be A Primary Key In Sql Server"