SQL Server clustered and nonclustered index instance _mssql

Source: Internet
Author: User
Tags create database
Create DATABASE Myindexdemo
Go
Use Myindexdemo
Go
CREATE TABLE ABC
(
A int NOT NULL,
B Char (10),
C varchar (10)
)
Go
INSERT INTO ABC
Select 1, ' B ', ' C '
Union
Select 5, ' B ', ' C '
Union
Select 7, ' B ', ' C '
Union
Select 9, ' B ', ' C '
Go

SELECT * FROM ABC

--Create a clustered index on the ABC table
Create clustered Index Clu_abc
On ABC (A)
Go

--View Index
Sp_helpindex ABC

--Inserting data
INSERT INTO ABC
VALUES (2, ' B ', ' C ')

--the physical structure of the entire table has changed because of the clustered index
--The contents of this index query are:
SELECT * from ABC with (index = CLU_ABC) WHERE a>1 and A<5

--After dropping the index
Drop index ABC. Clu_abc

--Query content in physical order or in order
SELECT * FROM ABC


--Create a nonclustered index on the ABC table
Create nonclustered index NONCLU_ABC
On ABC (A)

--View Index
Sp_helpindex ABC

--Inserting data
INSERT INTO ABC
VALUES (4, ' B ', ' C ')

--the physical structure of the entire table has changed because of the clustered index
--At this point the contents of the query are:
SELECT * from ABC with (index = NONCLU_ABC)

--After dropping the index
Drop index ABC. Nonclu_abc

--The physical order of the query content is in the order of insertion
SELECT * FROM ABC
Related Article

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.