MySQL's unique index unique

Source: Internet
Author: User

The purpose of creating a unique index is not to increase access speed, but to avoid duplication of data. A unique index can have more than one but the value of the indexed column must be unique, and the value of the indexed column allows for a null value. If you can determine that a data column will contain only values that are different from each other, you should use the keyword unique when creating an index for that data column and define it as a unique index.

Methods for creating unique cables

Action table

CREATE TABLE ' wb_blog ' (        ' id ' smallint (8) unsigned not NULL,        ' catid ' smallint (5) unsigned not N ULL default ' 0 ',        ' title ' varchar (+) NOT null DEFAULT ' ',        ' content ' text is not NULL,         PRIMARY KEY (' Id '),       )

1. Create a unique cable can be created with the table using the keyword unique

mysql> CREATE TABLE ' Wb_blog ' (     -   id ' smallint (8) unsigned not NULL,        ' CatID ' smallint (5) unsigned NOT null default ' 0 ',        ' title ' varchar (+) NOT null default ', 
       , ' content ' text not NULL,        PRIMARY KEY (' id '),         UNIQUE KEY ' catename ' (' catid ')     0 rows affected (0.24 sec)

The above code creates a unique index named Catename for the ' CATID ' field of the Wb_blog table

2. Create a table after creating it using the Create command

Mysql>0 rows affected (0.47 sec)

If you do not need a unique index, you can delete this

Mysql>0 rows affected (0.85 sec)

MySQL's unique index unique

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.