Difference between CHAR and NCHAR in MySQL

Q

What Are the Differences between CHAR and NCHAR in MySQL?

✍: FYIcenter.com

A

Both CHAR and NCHAR are fixed length string data types. But they have the following differences:

  • CHAR's full name is CHARACTER.
  • NCHAR's full name is NATIONAL CHARACTER.
  • By default, CHAR uses ASCII character set. So 1 character is always stored as 1 byte.
  • By default, NCHAR uses Unicode character set. NCHAR data are stored in UTF8 format. So 1 character could be stored as 1 byte or upto 4 bytes.
  • Both CHAR and NCHAR columns are defined with fixed lengths in units of characters.

The following column definitions are the same:

CREATE TABLE faq (Title NCHAR(80));
CREATE TABLE faq (Title NATIONAL CHAR(80));
CREATE TABLE faq (Title NATIONAL CHARACTER(80));
CREATE TABLE faq (Title CHAR(80) CHARACTER SET utf8);
CREATE TABLE faq (Title CHARACTER(80) CHARACTER SET utf8);

 

Difference between CHAR and VARCHAR in MySQL

Character String Data Types in MySQL

Introduction to SQL Basics in MySQL

⇑⇑ MySQL Database Tutorials

2018-01-19, 1746🔥, 0💬