Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHAR vs VARCHAR - no real difference size on disk 1

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
0
16
AU
Good morning all

I am looking for ways to optimize a database.
I have used CHAR field types for the database.
I took a look at the VARCHAR field type.
According to the documentation, VARCHAR only uses the size that it needs unlike CHAR that pads the field to the full width.
Therefore you would expect a table with a VARCHAR field to have less size on disk for a comparative example.

I created 2 tables with 2 fields each - autoinc ID field and character field width 100
One of the tables the character field is VARCHAR the other CHAR
I added 10k records to each with just one character in the text field.
Other than a minor difference of size, the size on disk was the same, about 10mb.

So what good is a varchar field if it does not save size on disk, is there something I am missing?
Other than the text from varchar fields not requiring TRIM() etc?
 
Varchar exists mostly to make it easier to move data in and out of remote tables. In VFP, all fields stored in a DBF are fixed-length. Period.

Tamar
 
Thanks Mike,
I won't be using remote views in this case, but very interesting to know, thankyou.


Alastair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top