mysql 等效数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2214901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql equivalent data types
提问by Blankman
I'm coming from a SQL Server background. What would the equivalent data types be for the following in MySQL:
我来自 SQL Server 背景。MySQL 中以下内容的等效数据类型是什么:
NVARCHAR
- provides support for international, multi-byte characters for all languages
NVARCHAR
- 支持所有语言的国际多字节字符
NVARCHAR(max)
- allows for very long text documents
NVARCHAR(max)
- 允许非常长的文本文档
采纳答案by Roland Bouman
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. So either one should work, and I would probably go for the latter since it is used more often.
据我所知,utf8 和 ucs2 两个字符集都允许使用相同的字符,只是编码不同。所以任何一个都应该工作,我可能会选择后者,因为它使用得更频繁。
There are some limitations in MySQL's unicode support that may or may not apply to your use case. Please refer to http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.htmlfor more info on MySQL's unicode support.
MySQL 的 unicode 支持存在一些限制,这些限制可能适用于您的用例,也可能不适用。有关 MySQL 的 unicode 支持的更多信息,请参阅http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html。
回答by Pentium10
the equivalent is VARCHAR
or TEXT
等价物是VARCHAR
或TEXT
MySql supports nchar and nvarchar but in a different way. 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 支持 nchar 和 nvarchar,但方式不同。这是使用字符集和排序规则实现的(这是一组用于使用字符集比较字符串的规则 - 例如比较是否应该区分大小写)。
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 参考进一步解释。
回答by CoryC
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.html
http://dev.mysql.com/doc/refman/5.0/en/charset-national.html