• 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.

More from my site

  • Java: How To Select Top N Objects From A ListJava: How To Select Top N Objects From A List
  • SQL: How To Select Data With Same Values On ColumnsSQL: How To Select Data With Same Values On Columns
  • Java: How To Use SQL LIKE Clasue with PreparedStatement?Java: How To Use SQL LIKE Clasue with PreparedStatement?
  • Java: Format Integer Into Fixed Width StringJava: Format Integer Into Fixed Width String
  • Java: Loading Large Data into JTable or JListJava: Loading Large Data into JTable or JList
  • SEO: Get Higher Ranking in Search EnginesSEO: Get Higher Ranking in Search Engines

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 Reply Cancel reply

Advertisement

  • Facebook
  • Google+
  • Instagram
  • Twitter

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

Adsense advertisement advertising apache blog blogging tips C# EGPC error estimation format format Integer Gmail Google Google Adsense Google Chrome Google Search Engine Google search result how to HTTP internet marketing Java JavaScript Linux money password performance PHP programming search engine optimization secure security short URL SQL static constructor String tiny URL Tips and Tricks twitter video Windows Vista Wordpress wordpress plugin wordpress theme Youtube

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