索引MySql TEXT列? [英] Indexing a MySql TEXT column?

查看:219
本文介绍了索引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中的列。

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列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆