SQL Server tutorial part 4 - Index


Indexes are used in SQL server to quickly retrieve the information

Type of Indexes

In SQL Server indexes are one of the following two types:
  1. Clustered Index 
  2. Non-Clustered Index. 

  • Clustered Index

A clustered index is the index that will arrange the rows physically in the memory in sorted order. An advantage of a clustered index is that searching for a range of values will be fast.

  • Non-clustered Index 

A non-clustered index is an index that will not arrange the rows physically in the memory in sorted order.  An advantage of a non-clustered index is searching for the values that are in a range will be fast. You can create a maximum of 999 non-clustered indexes on a table

Sample Table

Create Table customer(
CustomerId int not null Identity(1,1),
CustomerName varchar(100),
Primary Key(CustomerId)
)
Create Table CustomerDetails(
DetailsId int not null identity(1,1),
CustomerId int foreign key references Customer(CustomerId),
sort int,
refCode int
)

Create index

--non clustered and unique index
Create Unique Nonclustered Index U_refCode on CustomerDetails(
refCode desc
)
--non clustered and non unique index
Create Nonclustered Index NU_sort on CustomerDetails(
sort desc,
refCode asc
)

Drop index

Drop Index U_refCode

Please donate and support at https://www.paypal.me/Rajcoomar



Comments

Popular posts from this blog

Car Wash System vb.net

Face recognition using EmguCV 3.0 and typing pattern recognition

Student Information System - AngularJS , ASP.NET API, C#