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

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

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