Cita:
Empezado por Caral
Hola
Pero el varchar de 255 o menos no usa un byte?.
Por ahi me parecio leerlo.
Lo de la memoria no lo conocia.
Saludos
|
Sí, he leído casos que dicen una cosa y casos que dicen todo lo contrario :s
En este caso le viene mejor usar varchar.
Se debe usar char cuando hay un tamaño fijo, por ejemplo: el campo
Telefono char(9) almacenará 9 caracteres aunque lo dejemos en blanco.
El tipo varchar se debe usar cuando se necesite almacenar cadenas de longitud muy variable, por ejemplo: el campo
Incidencias varchar(1024) puede guardar cadenas desde 0 a 1024 caracteres. A veces se escribirá poco y otras mucho.
Cita:
Differences between CHAR and VARCHAR
Many people believe that VARCHAR is better because it stores only actual data, while CHAR is stored in full length. It is not true. In fact, both CHAR and VARCHAR are stored in memory buffer in their full, declared length; when the row is stored on disk, then RLE compression algorithm is used to compress whole row, i.e. CHARs, VARCHARs, INTEGERs, DATEs, etc. all together. So if you want to save space, CHARs are slightly better than VARCHARs (the differenece is that VARCHAR stores string length in two bytes). So decision whether use CHAR or VARCHAR should be based solely on application's requirements. E.g. store fixed length codes in CHAR, store names in VARCHAR (to allow correct concatenating).
|