使文本列为唯一键 [英] make text column as unique key

查看:143
本文介绍了使文本列为唯一键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 MySQL 中创建一个表格,其中 mediumtext 列为 UNIQUE KEY

i want to make a table in MySQL server with mediumtext column as UNIQUE KEY

CREATE TABLE `parts` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` mediumtext NOT NULL,
      `display_status` int(11) NOT NULL,
       UNIQUE KEY `name` (`name`),
       PRIMARY KEY (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

但发生错误

    BLOB/TEXT column 'name' used in key specification without a key length

当我把`name`的类型改为varchar ..它工作!

when i change the type of `name` to varchar .. it works !

你可以告诉我是否可以使文本列为UNIQUE KEY

can you tell if i can to make text column as UNIQUE KEY

感谢:)

推荐答案

基本上你不能使用文本列为 UNIQUE 键。因为实际上这样的大列不会是唯一的,并且可能有更多重复的机会。所以去 hashing 方法并使用该输出作为UNIQUE约束。

Basically you can not use Text column as UNIQUE key. Because practically such a big column will not be unique and there might be a chance of more duplicates. So go for hashing method and use that output as a UNIQUE constraint.

希望这有助于您

这篇关于使文本列为唯一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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