MS SQL Basics Tutorial: Creating indexes

Source: Internet
Author: User
Tags create index

8.2.1 CREATE index with the CREATE INDEX command

Create index either creates a clustered index that alters the physical order of the table or creates a nonclustered index that improves query performance. The syntax is as follows:

CREATE [UNIQUE] [CLUSTERED | Nonclustered]

INDEX index_name on {table | view} column [ASC | DESC] [,... N])

[With

[Pad_index]

[[,] FILLFACTOR = FILLFACTOR]

[[,] ignore_dup_key]

[[,] drop_existing]

[[,] statistics_norecompute]

[[,] sort_in_tempdb]

]

[ON filegroup]

The parameters are described as follows:

UNIQUE

Creates a unique index, where the key value of the index is not duplicated. You cannot build a unique index when a column contains duplicate values. To use this option, you should determine that the indexes contain columns that do not allow null values, or you will often make errors when you use them. CLUSTERED

Indicates that the index created is a clustered index. If this option is default, the index created is not a clustered index. Nonclustered

Indicates that the index created is not a clustered index. The data page contains pointers to the actual table data pages in the database. Index_name

Specifies the name of the index that is created. Index names should be unique in a table, but can be duplicated in the same database or in different databases. Table

Specifies the name of the table where the index is created. You should also indicate the database name and owner name, if necessary. View

Specifies the name of the view in which the index is created. The view must be defined using the SCHEMABINDING option, and its specific information is shown in the "View Creation" section. ASC | DESC

Specifies how a particular indexed column is sorted. The default value is ascending (ASC). Column

Specifies the column to be indexed. If you use two or more columns to make up an index, it is called a composite index. You can specify up to 16 columns in an index, but the data type of the column cannot be longer than 900 bytes. Pad_index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.