SQL Server clustered index and non-clustered index instance

Source: Internet
Author: User

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 ()
GO

-- View Indexes
Sp_helpIndex ABC

-- Insert data
Insert into ABC
Values (2, 'B', 'C ')

-- The physical structure of the entire table has changed because of clustered indexes.
-- The content queried Based on the index is:
Select * from abc with (index = CLU_ABC) where a> 1 and a <5

-- After the index is deleted
Drop index ABC. CLU_ABC

-- The physical order of the query content is still in order.
Select * from ABC


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

-- View Indexes
Sp_helpIndex abc

-- Insert data
Insert into ABC
Values (4, 'B', 'C ')

-- The physical structure of the entire table has changed because of clustered indexes.
-- The query content is:
Select * from abc with (index = NONCLU_ABC)

-- After the index is deleted
Drop index ABC. NONCLU_ABC

-- The physical order of the query content is in the insert order.
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.