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
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
Create index name on table (column name 1, column name 2 );
Add a unique index
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
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
show index from emp\G
3) delete an index
Drop index name on table name;
4) modify the index
Delete first, and then create
The end of this lecture is to talk about the price of indexes in the next lecture.