2

I'm using MariaDb server (Ver 15.1 Distrib 10.2.7-MariaDB). When I execute

CREATE TABLE `my_table` (
   `id` INT NOT NULL,
   `name` NVARCHAR(64) NULL,
   PRIMARY KEY (`id`)
);

Describe output:

MariaDB [db]> describe my_table;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(64) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Why there is no error, and "name" column datatype is varchar (not nvarchar)?

db schema details:

Default collation: utf8_general_ci
Default characterset: utf8
3
  • 4
    Maybe this part of the documentation helps: NATIONAL VARCHAR is the standard SQL way to define that a VARCHAR column should use some predefined character set. MariaDB uses utf8 as this predefined character set, as does MySQL 4.1 and up Commented Aug 16, 2017 at 8:13
  • @Jens - you literally beat me to it by 60 seconds. This is, IMHO, the "correct answer". Commented Aug 16, 2017 at 8:16
  • @Jens - The default continued to be latin1 for many versions. Finally, in 8.0, the default became utf8mb4. Commented Mar 6, 2019 at 3:30

1 Answer 1

6

NVARCHAR is a synonym for VARCHAR in MySQL/MariaDB. But you need to add the CHARACTER SET utf8mb4 to be sure that you get full UTF-8 support.

What you show as the default for that database is only the subset, called 'utf8'. It will not handle Emoji or some of Chinese.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.