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:
- Clustered Index
- Non-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.
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
| |
| |
| Create Unique Nonclustered Index U_refCode on CustomerDetails( |
| refCode desc |
| ) |
| |
| |
| Create Nonclustered Index NU_sort on CustomerDetails( |
| sort desc, |
| refCode asc |
| ) |
Drop index
Please donate and support at
https://www.paypal.me/Rajcoomar
Comments
Post a Comment