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 列?


基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01