Database optimization tutorial (6) index-related operations, tuning Indexes
Iii. Index
3. Index-related operations
In the previous section, we introduced the functions and types of indexes. This section describes the operations related to indexes!
1) Add an index
I have already introduced it. Here I will summarize it.
Add primary key index
[Plain]View plaincopy
- Create table aaa
- (Id int unsigned primary key auto_increment,
- Name varchar (32) not null defaul '');
- Alter table name add primary key (column name );
Add Common Index
[Plain]View plaincopy
- Create index name on table (column name 1, column name 2 );
Add a unique index
[Plain]View plaincopy
- Create table ddd (id int primary key auto_increment, name varchar (32) unique );
- Create unique index name on table name (list ..);
Add full-text index
[Plain]View plaincopy
- Create table articles (
- Id int unsigned AUTO_INCREMENT not null primary key,
- Title VARCHAR (200 ),
- Body TEXT,
- FULLTEXT (title, body)
- ) Engine = myisam charset utf8;
- Alter table articles add fulltext (title, body );
2) query Indexes
[Plain]View plaincopy
- Show index from emp \ G
3) delete an index
[Plain]View plaincopy
- Drop index name on table name;
4) modify the index
Delete first, and then create