当前位置:网站首页>How does MySQL create, delete, and view indexes?

How does MySQL create, delete, and view indexes?

2022-07-07 12:51:00 Full stack programmer webmaster

mysql It is an open source database with a wide range of applications .mysql The index inside can use pointers , Can greatly improve the query efficiency . Especially when the amount of data is very large , When a query involves multiple tables , Using indexes can often speed up queries thousands of times . that , How to create an index ?

  1. First step , Create a table , The structure is as follows :create table t (id int unsigned not null,name varchar(20) not null default ‘-‘);
  1. The second step , Add index , Second, the index is divided into several categories , General index , primary key , And unique index , The steps are shown in the figure : Number in the figure 123 It corresponds to the general index , primary key , And unique index alter table Table name add index/unique/primary key ( Index name );
  1. The third step , There is already an index in the table , How to check ? With these two commands :show index from table; or show keys from table; Pictured : show index from Table name ; show keys from Table name ;
  1. Step four , Sometimes there are too many indexes , It will cause the performance of adding, deleting, modifying and checking , So you can create it and delete it , The order is as follows : drop index Index name on Table name ; DROP INDEX index_name ON talbe_name; ALTER TABLE table_name DROP INDEX index_name; ALTER TABLE table_name DROP PRIMARY KEY;
  1. Step five , When deleting the index above , There was a mistake , Say that the index name cannot be found , Because it was deleted the first time , therefore , This index name no longer exists , Pictured
  1. Step six , Query the index again , Whether the deletion was successful , Repeat the command in step 3 , The result is shown in Fig. , The description has been deleted

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113449.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071036122323.html