tags:

views:

41

answers:

2

I would like to create table to storage short text. What is the best type to use.

char varchar

but i can't guarantee the text length. Any best practice ?

A: 

VARCHAR is the newer-style storage type for strings. Speaking from a MSSQL pov, VARCHAR offers many benefits over CHAR such as dynamic sizing, off-row storage for large values etc. I'd go with VARCHAR every time - unless I knew that the text was always going to be a fixed size.

Will A
Ok, but what lenght should i put in declaration ?
chris
The maximum length you foresee being stored in the field - plus 25% or so if you're not 100% confident in the size being correct.
Will A
A: 

If you are not sure about text length then i will suggest you should go with varchar.

you can just check,

http://bytes.com/topic/db2/answers/183253-varchar-vs-char

Yogesh
Ok, but what lenght should i put in declaration ?
chris
you can put the length whatever you want to be as max length. But varchar will only allocate that are required and not the max length. Max length only the upper limit for data storage. But before that you should also check the max limit that varchar can handle, you can not give more than that.
Yogesh