MySQL: String Data Types

Profile picture for user arilio666

we will see about the detailed review of string datatypes.

1. CHAR(size)

  • This data type is a fixed-length string containing characters, numbers, and special characters.
  • Within the size parameter, we can pass in the length of how long the string we want it to be.
  • It can be 0 to 255, and the default will be 1.

2. VARCHAR(size)

  • Variable-length string, same as char, can use letters, characters, special characters, etc.
  • Within the size parameter, we can pass in the length of how long the string we want it to be.
  • It can be from 0 to 65535.

3. BINARY(size)

  • Same as CHAR() but this one stores binary byte strings.
  • Within the size parameter, we can pass in the length of the string we want it to be, and size is specified in bytes.
  • The default size is one like CHAR.

4. VARBINARY(size)

  • Same as VARCHAR() but this one stores binary byte strings.
  • Within the size parameter, we can pass in the length of how long the string we want it to be, and size is specified in bytes of max column length.

5. TINY BLOB

  • This one is for large binary objects.
  • The maximum length used is 255 bytes.

6. TINY TEXT

  • It has a predefined length string that can hold up to 255 characters.

7. TEXT(size)

  • This one holds string up to the max length of 65,535 bytes.

8. BLOB(size)

  • This one is also for large binary objects.
  • Holds up to 65,535 bytes of data.

9. MEDIUMTEXT

  • This one holds a string with a max length of 16,777,215 characters.

10. MEDIUMBLOB

  • This can hold up to 16,777,215 bytes of data.

11. LONGTEXT

  • Can hold the string with max length up to 4,294,967,295 characters.

12. LONGBLOB

  • This one can hold up to 4,294,967,295 bytes of data.

13. ENUM(val1, val2, val3, ...)

  • This is a string object with only one value that can be chosen from a list of possible values.
  • Can be listed up to 65535 values.
  • A blank value will be listed if the value inserted is not in the list.
  • They sorted in the order we entered them.

14. SET(val1, val2, val3, ..)

  • This one is a string object that can have 0 or more values that are chosen from a list of possible values.
  • 64 values can be listed in this one.
Tags