EnjoY | Database Research And Development: SQL Server: Avoid the use of Indexes on VARCHAR columns

Saturday, August 29, 2020

SQL Server: Avoid the use of Indexes on VARCHAR columns


 I am also adding a Database Design category for this post, because what I am feeling that you guys must know about this before designing tables or indexes.

You can create Indexes on VARCHAR columns, but you should not create indexes on big size of VARCHAR Columns.

Indexes also require storing data as key for accessing associated records. There is a size limitation of index key values.

Before SQL Server 2016, Index key size limitation was 900 bytes for Clustered and Non-Clustered index column.
SQL Server 2016 increased this limitation for Non-Clustered Index and now it is up to 1700 bytes, but for Clustered Index column it is still 900 bytes.

Let me demonstrate this.

Create a sample table with Nonclustered Index:

You will get a below warning:
Because we have set Name VARCHAR(2000).

Try to insert 1701 bytes data:

You will get a below error:

You can successfully run below INSERT, because it inserts only 1700 bytes:

Now, create a sample table with Clustered Index:

You will get a below warning:
Because we have set Name VARCHAR(2000) on cluster index column.

Try to insert a over size data like more than 900 bytes:

You will get a below error:

You can successfully run below INSERT, because it inserts only 900 bytes:

No comments:

Post a Comment

It’s all about friendly conversation here at small review :) I’d love to be hear your thoughts!

Be sure to check back again because I do make every effort to reply to your comments here.

Featured Post

SQL Server : SELECT all columns to be good or bad in database system

This article is half-done without your Comment! *** Please share your thoughts via Comment *** In this post, I am going to write about one o...

Popular Posts