Loading

CHAR and VARCHAR MySQL Data Type

CHAR and VARCHAR Data Type:- The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved. CHAR and VARCHAR are declared with a fixed length, which declares how many a maximum number of characters will be stored.

When we create a table, the CHAR column will be fixed in length. The length value can be any value from 0 to 255 bytes. The stored CHAR value will be right padded with space to the specified length. When PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled, then trailing spaces will not remove after retrieving the CHAR value.

VARCHAR column value will be variable in length. Variable length value can be any value from 0 to 65,535 bytes. The effective maximum length of a VARCHAR is subject to the maximum row size. VARCHAR values are not padded when they are stored. Trailing spaces are retained when values are stored and retrieved.

Note:- If strict SQL mode will enable, values that exceed the column length are not stored, and an error results.

Example:-

CREATE TABLE employee(

Name VARCHAR(255),

Department CHAR(100)

);

Share with:


Leave a Reply

Connect with:





z35W7z4v9z8w