MySQL Learning note-index action statement

Source: Internet
Author: User

Using examples to illustrate how to view, delete, and add indexes, first create a table, as follows:

Mysql> CREATE TABLE Stu (
ID int,
, name char (5),
Key name (name),
Unique key ID (ID)
);

1. View the index of the table (two methods)

(1) Show index from table name;

(2) Show create table table name;

2. Delete the index of the table (two methods)

(1) ALTER TABLE name DROP INDEX name

After deletion, look at the index, the index name ID is deleted, only the name index,

(2) Drop index index name on table name

3. Add Index

ALTER TABLE name ADD [index,unique] Index name (column name), as

(1) Add a unique index to the ID column and view the table index

(2) Add a normal index to the Name column, and then view the table index

4. Finally operation of the primary key index

(1) Add primary KEY index: ALTER TABLE name add primary key (column name);

(2) Delete primary KEY index: ALTER TABLE name drop PRIMARY key;

MySQL Learning note-index action statement

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.