Home > Datatypes, SQL Queries, SQL Server, Stored Procedures, T-SQL > Advantages and differences between CHAR and VARCHAR datatypes in SQL Server

Advantages and differences between CHAR and VARCHAR datatypes in SQL Server

Everyone reading this must have come across these datatypes, but have you ever thought what are the differences and advantages between these two?

The obvious difference that comes to our mind is related to the length. Yes! You are right. The varchar supports variable length and Char supports fixed length. This is the main advantage varchar datatype. for example,  let us consider varchar(10) and char(10) . To store “GEEKEPISODE”, both the datatypes will use the complete length allocated and to store “GEEK”, CHAR datatype will use the complete 10 characters  allocated, but VARCHAR will use only 4.

From the above examples it might seem that VARCHAR is better than CHAR all the time. But remember, CHAR was included as a separate datatype because it has certain advantages over VARCHAR.

Advertisements
  1. May 28, 2013 at 1:49 pm

    I blog frequently and I really thank you for your information.
    This article has truly peaked my interest. I am going to book mark your blog and keep checking for new details about once a
    week. I subscribed to your RSS feed too.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: