gpt4 book ai didi

mysql 流畅 nhibernate 问题 nvarchar

转载 作者:行者123 更新时间:2023-11-29 08:54:13 26 4
gpt4 key购买 nike

我已经从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com