473,566 Members | 3,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CHAR vs VARCHAR

Hello,

In the DBMS I know best, PostgreSQL, there is no real performance
difference between CHAR and VARCHAR. And since CHAR pads with spaces, I
generally dislike CHAR (with CHAR, it's not possible to see if the input
value had trailing spaces or not, for example).

How is it in DB2?

More specifically: If a column has type CHAR(20) and most of the strings
have lengths between 5 and 15 characters, does it then make sense to use
CHAR(20)?

Are there any cases where CHAR are to be preferred over VARCHAR?

--
Regards,
Troels Arvin <tr****@arvin.d k>
http://troels.arvin.dk/
Feb 11 '07 #1
1 6610
"Troels Arvin" <tr****@arvin.d kwrote in message
news:eq******** **@news.net.uni-c.dk...
Hello,

In the DBMS I know best, PostgreSQL, there is no real performance
difference between CHAR and VARCHAR. And since CHAR pads with spaces, I
generally dislike CHAR (with CHAR, it's not possible to see if the input
value had trailing spaces or not, for example).

How is it in DB2?

More specifically: If a column has type CHAR(20) and most of the strings
have lengths between 5 and 15 characters, does it then make sense to use
CHAR(20)?

Are there any cases where CHAR are to be preferred over VARCHAR?

--
Regards,
Troels Arvin
A VARCHAR requires 2 extra bytes to store the length. So if the column width
is very small, or it is always filled to capacity, then it saves space to
use CHAR. There is also a very small amount of extra processing for VARCHAR,
but it is usually not measurable.

One other consideration is whether a VARCHAR column gets updated after it is
inserted. If the column is updated and it is now larger, then the row may
not fit back where it was, and it may not fit back on the same page. This
could result in overflow pages. This can be alleviated by using the proper
percent free on the table, and by doing frequent reorgs as needed to make
sure there is enough free space and to reorg any overflow rows.
Feb 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
6257
by: Randell D. | last post by:
Folks, I once read an article in Linux Format whereby a technical writer had made performance recommendations on a LAMP environment. One of the points raised was for small columns in a database, that one is perhaps better off to trade a small waste of space for a gain on performance - The recommendation said that when you use VARCHAR(3)...
5
29481
by: dmhendricks | last post by:
Greetings, I have a question. I work on some SQL2k/ASP.NET apps at work. My predacessor, who created the databases/tables seemed to have liked to use 'char' for all text fields. Is there a reason why he would have done this over using varchar? It's a minor annoyance to always have to RTRIM data and it makes directly making changes to...
5
10422
by: twkelsey | last post by:
Hi, My company has a scenario where we would like to change the data type of an existing primary key from an integer to a char, but we are concerned about the performance implications of doing so. The script for the two tables that we need to modify is listed below. Table FR_Sessions contains a column named TransmissionID which is...
10
71042
by: Techie | last post by:
what's the difference of the two data types?
22
11565
by: jdokos | last post by:
Hello, I have a question about VARCHAR fields. Our application groups here are starting to use VARCHARs much more frequently. Even VARCHAR (2) to (9) length fields. They say this is because some of the application programs, specifically Java Beans cannot handle the spaces after the value in CHAR fields. Is anyone else seeing this...
7
20437
by: D. | last post by:
Hi, I'm planning the structure of a SqlServer 2005 database for a new application. The requirement is that primary keys must be "natural"; i.e. in the table Customers the primary key will be a max. 10 characters string (but the string may be filled i.e. with only 5 charachters). Should I define these primary keys as char or varchar? I'm...
0
1347
by: Medhatithi | last post by:
I have a table whose indexed column is a char(16) field. I am giving the schema. CREATE TABLE Emp(Empno char(16), Ename varchar(25), Salary number(10,2),......) Now, there is an index on the Empno field. Now, inside a stored procedure, I am executing a statement select...
4
8855
by: Nick Chan | last post by:
all these while i've only used varchar for any string i heard from my ex-boss that char helps speed up searches. is that true? so there are these: 1) char with index 2) char without index 3) char with clustered index
0
27234
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications are constrained by the technology available at the time of their development and hence aren’t optimum as per current scenario. One of such cases is the...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.