如何在 MySQL 中创建 NVARCHAR 列?

mysqlmysqli database

MySQL 将 NVARCHAR() 转换为 VARCHAR()。NVARCHAR 代表 MySQL 中的 National Varchar。让我们首先创建一个表,其中一列"StudentName"为 NVARCHAR −

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

让我们检查一下表的描述 −

mysql> desc DemoTable;

这将产生以下输出。如下所示,NVARCHAR 类型的 StudentName 列在 MySQL 中自动转换为 VARCHAR −

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

使用 insert 命令在表中插入一些记录 −

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)

使用 select 语句显示表中的所有记录 −

mysql> select *from DemoTable;

这将产生以下输出 −

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

相关文章