Mysql - 更改表语句以在长文本字段上创建唯一索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9149861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:01:33  来源:igfitidea点击:

Mysql - Alter table statement to create unique index on long text field

mysql

提问by Matt Fenwick

I'm trying to create an Altercommand to create an unique_indexon the first 8000 characters. I'm not able to figure out how to add the 8000 part. Any help would be appreciated. Thanks!

我正在尝试创建一个Alter命令来unique_index在前 8000 个字符上创建一个。我无法弄清楚如何添加 8000 部分。任何帮助,将不胜感激。谢谢!

ALTER TABLE nextractor.tblhtml
  ADD UNIQUE INDEX uniqueindex_InnerHTML (InnerHtml);

回答by Matt Fenwick

According to the MySQL docs, you need something like this:

根据MySQL docs,你需要这样的东西:

alter table <table_name> 
  add unique index <index_name> (<column_name> (8000))


This is the relevant grammar:

这是相关的语法:

| ADD [CONSTRAINT [symbol]]
        UNIQUE [INDEX|KEY] [index_name]
        [index_type] (index_col_name,...) [index_option] ...

and

index_col_name:
    col_name [(length)] [ASC | DESC]

回答by rizon

ALTER TABLE nextractor.tblhtml ADD UNIQUE INDEX uniqueindex_InnerHTML (InnerHtml (8000));

ALTER TABLE nextractor.tblhtml 添加唯一索引 uniqueindex_InnerHTML (InnerHtml (8000));