MySQL VARCHAR 大小?

发布于 2024-11-30 14:09:59 字数 79 浏览 3 评论 0原文

如果我有一个 200 个字符的 VARCHAR 并且输入了一个 100 个字符的字符串,那么它会使用 200 个字节还是仅使用字符串的实际大小?

If I have a VARCHAR of 200 characters and that I put a string of 100 characters, will it use 200 bytes or it will just use the actual size of the string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遗忘曾经 2024-12-07 14:09:59

100 个字符。

这是 varchar 中的 var(变量):您只存储您输入的内容(以及额外的 2 个字节来存储最大长度 65535)

如果它是 char( 200) 那么你总是存储 200 个字符,并用 100 个空格填充

请参阅文档:"CHAR 和 VARCHAR 类型"

100 characters.

This is the var (variable) in varchar: you only store what you enter (and an extra 2 bytes to store length upto 65535)

If it was char(200) then you'd always store 200 characters, padded with 100 spaces

See the docs: "The CHAR and VARCHAR Types"

葵雨 2024-12-07 14:09:59

VARCHAR表示它是一个变长字符,所以它只是
将占用尽可能多的空间。但如果你知道一些事情
关于底层结构,限制 VARCHAR 可能是有意义的
达到某个最大数量。

例如,如果您要存储用户的评论,您可以
将评论字段限制为 4000 个字符;如果是这样,则不会
让 sql 表有一个更大的字段确实有意义
比 VARCHAR(4000)。

http://dev.mysql.com/doc/refman/5.0/en/char.html< /a>

VARCHAR means that it's a variable-length character, so it's only
going to take as much space as is necessary. But if you knew something
about the underlying structure, it may make sense to restrict VARCHAR
to some maximum amount.

For instance, if you were storing comments from the user, you may
limit the comment field to only 4000 characters; if so, it doesn't
really make any sense to make the sql table have a field that's larger
than VARCHAR(4000).

http://dev.mysql.com/doc/refman/5.0/en/char.html

执手闯天涯 2024-12-07 14:09:59

实际上,它需要 101 个字节。

MySQL 参考

Actually, it will takes 101 bytes.

MySQL Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文