Basic points to be considered when starting with SQL Server – – Part 1

I have been working with SQL from some time and I know how it feels when we start using it first time. Several questions arises in our mind like, Am I writing queries in correct way? What impact on my front end performance? What should I use? etc.

Let’s start answering these questions.

What should we use Char or Varchar?

This is the very common question most of the people ask with including me ;). Let me provide you some details.
We need to use char when we have a fixed size of the string for example: Mobile number it always has 10 digits. So the length is fixed so we can use char(10) for this.
We need to use varchar when the max length is known but length of the string may vary. For example:- Name, It can be at most 50 characters but not necessary that all persons should have 50 character names. varchar has 2 bytes(MS SQL Server) overhead to stores the length information of the string.

What should we use Nvarchar or Varchar?
Second thing that comes to the mind is what the difference between nvarchar and varchar is. Why we have two? When to use which one?
Let me try to help you with this.
Varchar only stores Non-Unicode charaters. So we should use varchar if the data is constraint for example:- Phone number, ETIN etc.
Nvarchar can store Unicode, Non-Unicode data. So we should use the Nvarchar is the data is not constrained for example:- we are supporting multilingual data.

Please keep in touch, I will post next part soon…..

<<Previous Post                                                                       Next Post>>

Written By: Ankit Arora, Sr. Software Engineer, Mindfire Solutions

Advertisements

Posted on January 15, 2014, in SQL and tagged , , , , , , . Bookmark the permalink. 1 Comment.

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: