| > | Computers > Databases > | |
CHAR vs. VARCHAR |
||
|
||||||||
|
||||||||
|
||||||||
|
|
Preview DRM-free music
Get information on your favorite TV Shows at Clarify the meaning of the acronyms on your web site. Register your own domain name at A to Z Domains. or buy domains at Domain Names For Sale .net
Printer-friendly PDF* format: |
Automatic padding of character columnsWhen considering whether to use CHAR or VARCHAR, the decision depends more on programming considerations than on the database. The difference is that comparisons of two fixed character fields will be automatically padded to equal lengths with spaces; comparisons with VARCHAR will not. Why not just make everything VARCHAR?In order to save time on the database design, you might be tempted to avoid using CHAR columns and simply use VARCHAR for all character data in the database. As a result, every time one of these columns is compared to a fixed character column or host variable, the programmers will have to use an RPAD or RTRIM function, since programming languages won't do automatic padding on VARCHAR columns. Because the database cannot simply search the values in the index when a function is applied to a key column queries may unexpectedly take much longer to complete. So the time that was saved in the design phase will probably be spent many times over trying to determine why certain queries are running so poorly. Fixed vs. variable length program variablesOne reason that the VARCHAR data type is often used is that some programmers by habit use variable
length character variables, which will also defeat the programming language's
automatic padding for fixed-length comparisons.
For example, in Java, programmers might simply use When to use CHAR vs. VARCHARIn database design, we're taught how to determine whether to make a column CHAR or VARCHAR.
You ask yourself, "is the length of the value significant?"
For example, if the column has up to 6 characters representing a gender,
is a 6-character " Last updated Tuesday November 14, 2006 |
You are currently viewing this page in HTML 4* format (* see Clicklets for more infomation). This document is also available in XHTML 1 Style Sheet*XHTML 1* XML*HTML 5 Style Sheet*HTML 5 XML*HTML 5 non-XML* XHTML 2* XHTML Mobile* WML Mobile* and printer-friendly PDF* formats. This is accomplished with Single Source Publishing, a content management system that uses templates in XSLT style sheets provided by XML Styles .com to transform the source content for various content delivery channels. There is also RDF* metadata that describes the content of this document.
Copyright © 2006 How To Guides .com. Alteration of content, including addition of any function such as hypertext links or pop-up advertising, or interference with the hypertext links or other functions of this site is expressly prohibited.
DISCLAIMER: All information, links, forms, applications and other items on this site or obtained from it are provided AS IS, WITHOUT WARRANTY OF ANY KIND EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.