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 across the situation.
Varchar(max) column not allowed to be a Primary Key in SQL Server.
It is perfectly acceptable to use a varchar column as the primary key. This is often the case when one uses a natural key that doesn't happen to be an integer.
VARCHAR(MAX) is different from VARCHAR because it supports character strings up to 2 GB (2,147,483,647 bytes) in length. You should consider using VARCHAR(MAX) only when each string stored in this data type varies considerably in length, and a value might exceed 8000 bytes in size.
VARCHAR(255) stores 255 characters, which may be more than 255 bytes.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With