What is the use of NCHAR in MySQL?


MySQL defines NCHAR as a way to indicate that a CHAR column should use predefined character set. Utf8 is used by MySQL as its predefined character set.

Example

In the example below, we are creating a table named ‘Student1’. In this table, we are declaring the data types of three columns with three different declaration styles which are rather equivalent of each other. It is all due to NCHAR.

mysql> Create table Student1(Name Char(10) character set utf8, Address NATIONAL CHARACTER(10), FatherName NCHAR(10));
   Query OK, 0 rows affected (0.25 sec)

Now on checking the status of table, with the help of query below, we can see that all the declaration styles are same.

mysql> show create table Student1\G

*************************** 1. row ***************************
Table: Student1
Create Table: CREATE TABLE `student1` (
    `Name` char(10) CHARACTER SET utf8 DEFAULT NULL,
    `Address` char(10) CHARACTER SET utf8 DEFAULT NULL,
    `FatherName` char(10) CHARACTER SET utf8 DEFAULT NULL
    ) ENGINE = InnoDB DEFAULT CHARSET = latin1

1 row in set (0.00 sec)

Updated on: 20-Jun-2020

664 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements