mysql 流畅 nhibernate 问题 nvarchar

标签 mysql nhibernate fluent-nhibernate

我已经从 sql server 2005 切换到 mysql,这并不是一个真正的问题。

我对 sql server 中存在的 (n)varchar 有一个小问题。通常我用过:

mapping.Map(x => x.bla).Length(10000);

将 bla 设置为 nvarchar(max)。这在mysql中有效吗?我相信mysql中没有nvarchar,你必须使用这样的东西:

alter table sometable modify bla VARCHAR(21844) CHARACTER SET utf8

将现有列更新为“nvarchar(max)”。这是正确的吗,因为我得到:

“行大小太大。所使用的表类型的最大行大小”

如果我使用:

alter table sometable modify bla VARCHAR(1000) CHARACTER SET utf8

一切正常,但我不确定这是否能在 mysql 中实现“nvarchar(max)”。

最佳答案

the manual 中所述:

Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. Storage engines may place additional constraints on this limit, reducing the effective maximum row size.

The maximum row size constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size. For example, utf8 characters require up to three bytes per character, so for a CHAR(255) CHARACTER SET utf8 column, the server must allocate 255 × 3 = 765 bytes per value. Consequently, a table cannot contain more than 65,535 / 765 = 85 such columns.

Storage for variable-length columns includes length bytes, which are assessed against the row size. For example, a VARCHAR(255) CHARACTER SET utf8 column takes two bytes to store the length of the value, so each value can take up to 767 bytes.

因此,您必须考虑表中存在哪些其他列,并计算此 VARCHAR 可用的最大大小。

但是,如果您需要为长文本值留出空间,为什么不使用 TEXT不受此限制约束的数据类型(除了它们贡献的 9 到 12 字节)?

关于mysql 流畅 nhibernate 问题 nvarchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395644/

相关文章:

nhibernate - 配置 Nhibernate 日志到文件中

nhibernate - 希望加入的路径!休眠错误

mysql - 批量 INSERT INTO mySQL 或 none insert none 如果有错误 VB.Net

javascript - 根据用户位置查询数据库值

c# - 子类的映射列表

nhibernate - fluent nhibernate r1.0 fluent 映射禁用延迟加载

Nhibernate Throws找到对集合的共享引用

mysql - 如何使用 MAMP 查找服务器 ID

mysql - 从多个线程访问大型数据库表

NHibernate、AutoMapper 和 ASP.NET MVC