
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What should one use CHAR data type or VARCHAR data type in MySQL?
Actually, both of these data types in MySQL store strings and can be set with a maximum length. The use of these data types purely depends on the need. Followings are some points which will make us clear that when one should CHAR and when VARCHAR −
- Suppose if we have fixed size of data, such as flags of “Y” and “N” then it is better to use CHAR rather than VARCHAR. It is because 1 byte of length prefix also used with VARCHAR. In other words, for the above kind of data, CHAR will store the only 1byte which is the data only and VARCHAR will store 2 bytes (1 byte for data and 1 byte for length prefix).
- If we want to store the data such as usernames and passwords or any other variable-length data then it is better to use the VARCHAR data type because then we would be able to store data without wasting extra space.
- Related Articles
- Which one should I use? The datetime or timestamp data type in MySQL?
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- In MySQL, when VARCHAR data type will use 1-byte and when 2-bytes prefix length along with data?length along with data?
- What data type to use for hashed password field in MySQL?
- What is BLOB data type in MySQL?
- What is TEXT data type in MySQL?
- Change Data Type for one or more columns in Pandas Dataframe
- Change Data Type for one or more columns in Pandas Dataframe
- What is the data type for unix_timestamp in MySQL?
- Abstract Data Type in Data Structures
- Why we cannot use MySQL DATE data type along with time value?
- How MySQL use YEAR data type to store year value in a table?
- How to use blob data type in Android sqlite?
- How to use real data type in Android sqlite?
- what are the different attributes of MySQL ENUM data type?

Advertisements