Home >Database >SQL >What is the purpose of creating an index for a data table?

What is the purpose of creating an index for a data table?

hzc
hzcOriginal
2020-06-19 13:18:1218110browse

What is the purpose of creating an index for a data table?

1. The purpose of creating an index in SQL is as follows:

1. Unique index (unique) can ensure the uniqueness of data;

2 , speed up data retrieval;

3, speed up the connection between tables;

4, reduce grouping and sorting time;

5, use optimization hider to improve the system performance.

2. Syntax for creating SQL index:

CREATE [UNIQUE] [CLUSTERED| NONCLUSTERED](索引类型) INDEX <索引名> ON <表名>(<列名> [ASC|DESC] 
[, <列名>[ASC|DESC]...])。

What is the purpose of creating an index for a data table?

Extended information:

Introduction to index categories:

1. Unique index:

A unique index is an index that does not allow any two rows to have the same index value. Most databases do not allow newly created unique indexes to be saved with the table when there are duplicate key values ​​in the existing data. The database may also prevent adding new data that would create duplicate key values ​​in the table.

2. Primary key index:

Database tables often have one column or a combination of columns, whose values ​​uniquely identify each row in the table. This column is called the primary key of the table. Defining a primary key for a table in a database diagram automatically creates a primary key index, which is a specific type of unique index. The index requires each value in the primary key to be unique. It also allows fast access to data when using a primary key index in a query.

Recommended tutorial: "mysql tutorial"

The above is the detailed content of What is the purpose of creating an index for a data table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn