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 wOOdy-Soft 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

Status
Not open for further replies.

Ginka

Programmer
Mar 18, 2005
54
MX
SQL Server Documentations says:

char = Fixed-length non-Unicode character data with a maximum lebgth of 8000 characters.

varchar = Variable-length non-Unicode data with a maximum length of 8000 characters.

if I want fields Name & LastName which should I use and why?

so what's the difference between fixed & variable length?
 
Fixed always uses the same amount of space to store the data. Includes additional blank spaces for remaining charachers. Variable only uses the space needed to store the data:

Ex: "Ginka"
stored in a char(10) would be returned as "Ginka "
stored in a varchar(10) would be returned as "Ginka"
 
thank you!!!
I always had that doubt.
 
Sorry - I didn't answer the second part of your question:

The reason you would use a char versus a varchar is when you have a fixed length value like a code for a code table. I've read that char works better for columns you want to search on but for storing variable length data, I always use varchar.
 
BTW, Varchar and NVarchar always include a bit of "overhead" in SQL so that the field can expand as needed. So if you are doing math to figure out how much hard drive space or .MDF file space you'll need for your database, include the max limit of all variable length characters and add just a little bit extra for the C.Y.A. portion of the exercise.



Catadmin - MCDBA, MCSA
Beware the error of pre-emptive poultry inventory!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top