Varchar (max) column cannot be SQL Server primary key

The Varchar (max) column cannot be the primary key of SQL Server.

What is the maximum length of the varchar type that can be made the primary key.

This may be bad practice, but came across a situation.

+8
sql sql-server
source share
3 answers

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

+16
source share

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

+4
source share

The primary key is used in all other indexes to identify rows. The presence of a potentially large megabyte value as a key makes very little sense, therefore, the general restriction on shared bytes in any key.

+3
source share

All Articles