Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

People also ask

How do I add a unique index to an existing table?

Right-click the table on which you want to create a unique index and select Design. On the Table Designer menu, select Indexes/Keys. In the Indexes/Keys dialog box, click Add. Select the new index in the Selected Primary/Unique Key or Index text box.

How do I create a composite unique index in MySQL?

Creating Composite IndexCREATE TABLE table_name ( c1 data_type PRIMARY KEY, c2 data_type, c3 data_type, c4 data_type, INDEX index_name (c2,c3,c4) ); In the above statement, the composite index consists of three columns c2, c3, and c4.

How do I create a unique field in MySQL?

The syntax for creating a unique constraint using an ALTER TABLE statement in MySQL is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.

Does unique constraint CREATE INDEX in MySQL?

If we use a UNIQUE constraint in the table, MySQL automatically creates a UNIQUE index behind the scenes. The following statement explains how to create a unique constraint when we create a table.


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

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]

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