How to create NVARCHAR column in MySQL?


The MySQL converts NVARCHAR() to VARCHAR(). NVARCHAR stands for National Varchar in MySQL. Let us first create a table with one of the columns “StudentName” as NVARCHAR −

mysql> create table DemoTable
(
   StudentName NVARCHAR(40),
   StudentCountryName VARCHAR(50)
);
Query OK, 0 rows affected, 1 warning (0.49 sec)

Let us check the description of the table −

mysql> desc DemoTable;

This will produce the following output. As you can see below, the StudentName column with NVARCHAR type is automatically converted to VARCHAR in MySQL −

+--------------------+-------------+------+-----+---------+-------+
| Field              | Type        | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+-------+
| StudentName        | varchar(40) | YES  |     | NULL    |       |
| StudentCountryName | varchar(50) | YES  |     | NULL    |       |
+--------------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Chris','US');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Tom','UK');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('David','AUS');
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-------------+--------------------+
| StudentName | StudentCountryName |
+-------------+--------------------+
| Chris       | US                 |
| Tom         | UK                 |
| David       | AUS                |
+-------------+--------------------+
3 rows in set (0.00 sec)

Updated on: 04-Oct-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements