Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of creating indexes in mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the methods of mysql to create an index, I hope you will learn a lot after reading this article, let's discuss it together!

You can create an index when you execute a CREATE TABLE statement, or you can add an index to a table using CREATE INDEX or ALTER TABLE alone.

1.ALTER TABLE

ALTER TABLE is used to create normal, UNIQUE, or PRIMARY KEY indexes.

ALTER TABLE table_name ADD INDEX index_name (column_list) ALTER TABLE table_name ADD UNIQUE (column_list) ALTER TABLE table_name ADD PRIMARY KEY (column_list)

Where table_name is the name of the table to be indexed, column_list indicates which columns are indexed, and multiple columns are separated by commas. The index name index_name is optional, and by default, MySQL assigns a name based on the first index column. In addition, ALTER TABLE allows multiple tables to be changed in a single statement, so multiple indexes can be created at the same time.

2.CREATE INDEX

CREATE INDEX can add a normal index or an UNIQUE index to a table.

CREATE INDEX index_name ON table_name (column_list) CREATE UNIQUE INDEX index_name ON table_name (column_list)

Table_name, index_name, and column_list have the same meaning as in the ALTER TABLE statement, and the index name is not optional. In addition, PRIMARY KEY indexes cannot be created with CREATE INDEX statements.

After reading this article, I believe you have a certain understanding of mysql's method of creating an index. I would like to know more about it. Welcome to follow the industry information channel. Thank you for your reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report