The concept of an index
In a relational database, an index is a structure that sorts the values of one or more columns in a database table.
Types of indexes in SQL Server:
Differentiated by storage structure: Clustered index (also known as Cluster index, cluster index), clustered index (nonclustered index, non-clustered index)
Differentiated by Data uniqueness: "Unique index", "non-unique index"
Number of key columns: "single column Index", "Multi-column index"
Differences in clustered and nonclustered indexes
Clustered index: is the actual data on the disk is re-organized to sort by a specified column or columns of values. A table can only establish one clustered index. (compared to the Xinhua dictionary by pinyin Search)
Nonclustered indexes: SQL Server creates an index that is not a clustered index by default, he does not reorganize the data in the table, but instead stores the index column values on each row and points to the page where the data resides. A table can have multiple nonclustered indexes, and each nonclustered index provides a different sort order based on the different indexed columns. (compared to Xinhua dictionary search by the Radicals)
Syntax for indexes
CREATE [UNIQUE] [clustered| Nonclustered] INDEX index_name | view} (column [ASC | DESC] [,... n]) [with[pad_index][[,]fillfactor=FILLFACTOR] [[,]ignore_dup_key] [[,]drop_existing] [[,]statistics_norecompute] [[,]sort_in_tempdb] ] [ON filegroup]
Index syntax interpretation
The CREATE INDEX command creates indexes for each parameter description as follows:
Unique: Used to specify that a unique index is created for a table or view, that is, two rows with the same index value are not allowed.
CLUSTERED: Used to specify that the index created is a clustered index.
Nonclustered: Used to specify that the index created is a nonclustered index.
Index_name: Used to specify the name of the index being created.
Table: Specifies the name of the table on which the index is created.
View: Specifies the name of the view that created the index.
asc| DESC: Used to specify an ascending or descending sort direction for a specific index column.
Column: Used to specify the columns to be indexed.
PAD_INDEX: Used to specify the space that remains open on each page (node) in the intermediate level of the index.
FILLFACTOR = FILLFACTOR: Used to specify that the data for each index page is a percentage of the index page size when the index is created, and the value of FILLFACTOR is 1 to 100.
Ignore_dup_key: Used to control the response of SQL Server when inserting duplicate data into a column that is contained in a unique clustered index.
Drop_existing: Used to specify that a named pre-existing clustered index or nonclustered index should be dropped and recreated.
Statistics_norecompute: Index statistics used to specify expiration are not automatically recalculated.
SORT_IN_TEMPDB: Used to specify that intermediate sorting results are stored in the TEMPDB database when the index is created.
ON filegroup: Used to specify the filegroup to hold the index.
Index design principles
Manage Indexes
Exec sp_helpindex bigdata--'bigdata.idx_mobiel','Idx_big_mobiel ' --Change the index name from 'idx_mobiel' to 'idx_big_mobiel 'drop Index Bigdata.idx_big_mobiel-------Update the statistics of all indexes in the Bigdata table
Advantages and disadvantages of indexes
Advantages
1. Greatly accelerate the retrieval speed of data;
2. Create a unique index that guarantees the uniqueness of each row of data in a database table;
3. Accelerate the connection between tables and tables;
4. When using grouping and sorting clauses for data retrieval, you can significantly reduce the time to group and sort in queries.
Disadvantages
1. The index needs to occupy physical space.
2. When the data in the table is added, deleted and modified, the index should be maintained dynamically, reducing the maintenance speed of the data.
Considerations when working with indexes:
Avoid calculating operations on indexed fields
Avoid using not,<>,!= on indexed fields
Avoid using is null and is not NULL on indexed columns
Avoid data type conversions on indexed columns
Avoid using functions on indexed fields
Avoid using null values in indexed columns.
"SQL"-Basic knowledge grooming (vii)-index