Database-Index

Index overview:

It is a separate, physical data structure. The index is built on the table. It provides an internal method for arranging the data in the table in the database. The storage of a table is composed of two parts, storing the data page of the table and storing the index page .

Once the index is created, it will be automatically managed and maintained by the database, which can improve the efficiency of fast access

advantage:

  • Ensure the uniqueness of data records
  • Speed ​​up data retrieval
  • Speed ​​up the connection between the table and the table
  • When using ORDER BY and GROUT BY clauses to retrieve data, you can significantly reduce the time of grouping and sorting in the query
  • The hider can be optimized in the process of retrieving data

Create index:

CREATE

[UNIQUE][CLUSTERED|NONCLUSTERED]'(mini, 1 cluster, multiple non-aggregates)

INDEX index name

On

Table_name | view_name

(column_name[1,…,n])

Delete index:

DROP index table name. Index name

Create a schema

CREATE SCHEMA schema_name_clause [ <schema_element> […n]]

<schema_name_clause> ::=

{

Schema_name

|AUTHORIZATION owner_name

}

<schema_element>::=

{

Table_definition | view definition | grant_statement

Revoke_statement | deny_statement

}

Clustered index and non-clustered index

The clustered index determines the physical order of the data in the table. A table can only contain one clustered index. The clustered index is particularly effective for columns that often need to search for range values

Under what circumstances use clustered index:

  • Column with a lot of distinct values
  • Use BETUEEN, >, >=, <or <= to return a column of range values
  • Columns that are accessed consecutively
  • Queries that return large result sets
  • Columns that are frequently accessed by queries that use joins or GROUP BY clauses

The data of the non-clustered index is stored in one location, the index is stored in another location, the items in the index are stored in the order of the index value, and the information in the table is stored in another order

The maximum number of non-clustered indexes that can be created in each table is 249

The important difference between the two:

Data rows are not sorted and stored in the order of non-clustered index keys

The leaf layer of a nonclustered index does not contain data pages. Instead, leaf nodes contain index rows.

Guess you like

Origin blog.csdn.net/TGB_Tom/article/details/103880670