Data types for character columns

Data types for character columns

In MySQL, character columns can store textual data in various formats, including strings, text, and binary data. The following are the commonly used character data types in MySQL:

  1. CHAR: This data type is used to store fixed-length character strings. It can hold up to 255 characters, and if the string is shorter than the defined length, the remaining spaces are padded with spaces.
  2. VARCHAR: This data type is used to store variable-length character strings. It can hold up to 65,535 characters, and if the string is shorter than the defined length, it does not pad spaces.
  3. TEXT: This data type is used to store large text values of up to 65,535 bytes. It is ideal for storing long textual data such as blog posts, articles, or comments.
  4. BLOB: This data type is used to store binary data, such as images, videos, and audio files. It can hold up to 65,535 bytes of data.
  5. ENUM: This data type is used to store a predefined set of values that represent string literals. It can hold up to 65,535 different values.
  6. SET: This data type is used to store multiple predefined values that represent string literals. It can hold up to 64 different values.

In conclusion, the choice of character data type depends on the nature of the data you want to store. For instance, if you want to store a fixed-length string, use CHAR, but if you need to store a variable-length string, use VARCHAR. Similarly, use TEXT for long textual data and BLOB for binary data.

Apply for MySQL Certification!

https://www.vskills.in/certification/certified-mysql-db-administrator

Back to Tutorials

Share this post
[social_warfare]
Constraints, indexes and views
Data Manipulation

Get industry recognized certification – Contact us

keyboard_arrow_up