• Home
  • About

Snippet IT

IT News, Programming, Internet and Blogging

  • Programming and Scripting
  • Tips and Tricks
  • Software and Hardware
  • New and Happening
You are here: Home / Programming and Scripting / Database: CHAR and VARCHAR – What are the differences?

Database: CHAR and VARCHAR – What are the differences?

May 30, 2010 by Sze Hau Leave a Comment

Most programmers may already know the main different between CHAR and VARCHAR – The first one supports fixed-length data and the second one supports variable-lengths of data.

Some people may think, since VARCHAR can do what CHAR does, then why we still need CHAR in our database design. I even have heard one of the very experienced Oracle database administrator say “Nowadays nobody is using CHAR anymore, you can forget about putting CHAR column in your database design”.

The statement is not totally right. Even though VARCHAR can do what CHAR does, CHAR does has certain level of advantages over VARCHAR in terms of performance, efficiency and space.

I think it is good for a database designer to know how a database is being design. In other words, to think how a database programmer will design the database management system (DBMS) for the best performance and efficiency.

1. When a table column size is quite small, for instance 1 to 4 bytes, using CHAR helps save more space then VARCHAR. This is because DBMS will need additional few bytes (depends on database limitation for VARCHAR) to keep track the length of the data (all the rows) for the VARCHAR column.

2. Since VARCHAR can keep variable size of data, therefore it needs to keep track the length of the data for all the records. Therefore it adds little overhead to the DBMS’s performance if compared to CHAR.

3. DBMS (I would say most systems) keeps fixed-length data and index more efficiently. Retrieving and updating data from and to a fixed-length row table is faster then a variable-length row table.

Therefore, I think CHAR is still very useful. We should always use CHAR if the column size is small enough or the data input is always going to be the size of the column (e.g. most of the data is in 10-12 bytes size and the column size is 12 bytes), so that we can get better performance for our application.

Filed Under: Programming and Scripting Tagged With: database, DBMS, performance, search engine optimization, SQL

About Sze Hau

Geek. Love programming. Coffee addicted. Married with two children. Working towards financial freedom.

Leave a ReplyCancel reply

Advertisement

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

Software and Hardware

MD5 and SHA1 Checksum Using Windows

July 5, 2017 By Sze Hau Leave a Comment

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • szehau's weblog Life, Internet, Software, Gadgets, Programming and Investments

Snippet IT

This is the place where I want to share anything about information technology.

Search

Recent

  • MD5 and SHA1 Checksum Using Windows
  • MD5 and SHA1 Checksum Using Linux
  • Java: Unlimited Strength Jurisdiction Policy
  • WordPress: How To Change Admin Username
  • Linux: How To Compress And Decompress Folders And Files

Tags

advertisement blog C# Chrome DecimalFormat EGPC Float format format Integer free icons Gmail Google Google Adsense Google Chrome Google Search Engine Google search result how to HTTP Java JavaScript Linux money password performance PHP programming search engine optimization secure security short URL site value spam SQL static constructor String thread tiny URL Tips and Tricks trackback twitter video Wordpress wordpress plugin wordpress theme Youtube

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in