Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;

but this made an error

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
444 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...