简体   繁体   English

mysql 等效数据类型

[英]mysql equivalent data types

I'm coming from a SQL Server background.我来自 SQL Server 背景。 What would the equivalent data types be for the following in MySQL: MySQL 中以下内容的等效数据类型是什么:

NVARCHAR - provides support for international, multi-byte characters for all languages NVARCHAR - 支持所有语言的国际多字节字符

NVARCHAR(max) - allows for very long text documents NVARCHAR(max) - 允许非常长的文本文档

Going by http://msdn.microsoft.com/en-us/library/ms186939.aspx , I would say that通过http://msdn.microsoft.com/en-us/library/ms186939.aspx ,我会说

VARCHAR(n) CHARSET ucs2

is the closest equivalent.是最接近的等价物。 But I don't see many people using this, more often people use:但我没有看到很多人使用这个,更多的人使用:

VARCHAR(n) CHARSET utf8

As far as I am aware, both charactersets utf8 and ucs2 allow for the same characters, only the encoding is different.据我所知,utf8 和 ucs2 两个字符集都允许使用相同的字符,只是编码不同。 So either one should work, and I would probably go for the latter since it is used more often.所以任何一个都应该工作,我可能会选择后者,因为它使用得更频繁。

There are some limitations in MySQL's unicode support that may or may not apply to your use case. MySQL 的 unicode 支持存在一些限制,这些限制可能适用于您的用例,也可能不适用。 Please refer to http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html for more info on MySQL's unicode support.有关 MySQL 的 unicode 支持的更多信息,请参阅http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html

the equivalent is VARCHAR or TEXT等价物是VARCHARTEXT

MySql supports nchar and nvarchar but in a different way. MySql 支持 nchar 和 nvarchar,但方式不同。 This is implemented using character set and collation (which is a set of rules used for comparison of strings using the character set - such as whether the comparison should be case sensitive or not).这是使用字符集和排序规则实现的(这是一组用于使用字符集比较字符串的规则 - 例如比较是否应该区分大小写)。

MySql defines character set at 4 level: MySql 定义了 4 个级别的字符集:

Server服务器
Database数据库
Table桌子
Column柱子

character set is inherited from the immediate top level if you do not specify one.如果不指定字符集,则从最直接的顶层继承字符集。 What you need to do is to ensure that the column that you want to make of type nvarchar has "character set" set to any unicode character set (utf8 is the best choice I believe) either explicitly or by inheritance.您需要做的是确保您要创建的 nvarchar 类型的列将“字符集”设置为任何 unicode 字符集(我认为 utf8 是我认为的最佳选择),无论是显式还是通过继承。

For column level you can set "character set" as follows:对于列级别,您可以按如下方式设置“字符集”:

create table nvarchar_test
(
_id varchar(10) character set utf8,
_name varchar(200) character set ascii
)

In the above example _id will be able to take 10 unicode characters and _name will be able to take 100 unicode characters (each unicode character will evaluate to two ascii character)在上面的例子中 _id 将能够接受 10 个 unicode 字符,_name 将能够接受 100 个 unicode 字符(每个 unicode 字符将评估为两个 ascii 字符)

Please go through MySql reference for further explanation.请通过 MySql 参考进一步解释。

In MySQL 5, NVARCHAR (shorthand for National Varchar) is supported and uses utf8 as the predefined character set.在 MySQL 5 中,支持 NVARCHAR(National Varchar 的简写)并使用 utf8 作为预定义字符集。

http://dev.mysql.com/doc/refman/5.0/en/charset-national.htmlhttp://dev.mysql.com/doc/refman/5.0/en/charset-national.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM