Indexing a MySql TEXT column?(索引 MySql TEXT 列?)
问题描述
我使用 MySql 运行它,但它似乎不喜欢 TEXT
.对于 SQL 服务器,我使用 nvarchar(max)
我应该在 MySql 中使用什么?在其他表格中,一些字段将是描述并且可能很长,所以目前我认为固定长度是不好的.
I ran this using MySql and it appears to not like TEXT
. With SQL server I use nvarchar(max)
What should I use in MySql? In other tables some fields will be descriptions and may be long so at the moment I am thinking that fixed length is bad.
create table if not exists
misc_info (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
key TEXT UNIQUE NOT NULL,
value TEXT NOT NULL
)ENGINE=INNODB;
推荐答案
MySQL 中的文本列不能有 UNIQUE 索引.
You can't have a UNIQUE index on a text column in MySQL.
如果要在 TEXT 或 BLOB 字段上建立索引,则必须指定固定长度才能做到这一点.
If you want to index on a TEXT or a BLOB field, you must specify a fixed length to do that.
来自 MySQL 文档:
BLOB 和 TEXT 列也可以索引,但前缀长度必须是给.
BLOB and TEXT columns also can be indexed, but a prefix length must be given.
示例:
CREATE UNIQUE INDEX index_name ON misc_info (key(10));
这篇关于索引 MySql TEXT 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:索引 MySql TEXT 列?


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01