Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Index in SQL Server Explain with simple Way - Part Two Introduction This article explains about Non Cluster index in SQL Server with simple way. Many Fresher and students are struggling to get understanding about index in SQL server, so this article explains about index with simple way with examples. Before read this article please refer previous part of this article. Definition Index is a SQL Object. It is a data structure that improves the speed of data retrieval operations. Index is a one of query optimizer and it is used to increase the performance. There are following types of index in SQL Server. 1. Cluster Index 2. Non Cluster index non Non Cluster Index Non Cluster index is one of SQL object. We often used this index in SQL Server. We can create more than one non cluster index in a table. Non cluster index are stored in memory as logically. Non cluster index is stored as binary tree format. Non cluster index will be store in order based on index key value. We can divide Non cluster index into following type. 1. 2. 3. 4. Non Cluster Index Unique Non Cluster Index Composite Non Cluster Index Unique Composite Non Cluster Index Non Cluster Index We can create non cluster index to a fields or columns in table. We can create following way to create a non cluster index. This is will accept duplicate values. Example Query CREATE NONCLUSTERED INDEX IX_Person_FirstName ON Person(FirstName) We creating Non cluster index for FirstName columns in “Person” table. After crate we can enter values and at the same can enter duplicate into table. Below screen shorts shows we can enter duplicate value in non cluster index We can see index which one we created for our table. Open object explore and go to database then go to corresponding table under database. Now expand the table then expand index under the table. Below screen short shows index name and type of index name. non cluster index is non-unique. We can create more than one non cluster index in a table with different index name. Below screen short shows how can create more than one non cluster index a table. If try to create non cluster index in same name will be getting error. When move the cursor on the index name we can see the alert message like below screen short. Unique Non Cluster Index Unique non cluster index only accept the unique values. It is not accept duplicate values. Example Query CREATE UNIQUE NONCLUSTERED INDEX IX_Person_FirstName ON Person(FirstName) After creating unique non cluster index, we cannot insert duplicate value in table which field created unique. First we insert three records into “Person” table and it will be executing without error. Now again insert already inserted first name value in FirstName column into table, it getting error look below screen shorts. Note: We can create unique non cluster index after inserting records in a table. If have duplicate records in table, we get error while creating unique non cluster index cluster index Composite Non Cluster Index Create non cluster index combination of more than one column name in a table or more than one field is call composite non cluster index. We can insert duplicate values into table if also created composite cluster index. Example Query CREATE NONCLUSTERED INDEX IX_Person_FirstLastName ON Person(FirstName,LastName) We created non cluster index for combination of two columns one for “FirstName” and another one for “LastName” in Person table. This is called composite cluster index. Composite non cluster index accept duplicate records for example find below screen shorts. Unique Composite non cluster index Unique composite non cluster index is a combination of Unique and composite non cluster index. It is not accept duplicate vales. Example CREATE UNIQUE NONCLUSTERED INDEX IX_Person_FirstLastName ON Person(FirstName,LastName) After create unique composite non cluster index we can not enter duplicate value with compination of two columns. For example we insert three records with different value then fourth one try to insert Same “FirstName” and “LastName” but it getting error because of unique composite non cluster index. Below screen shorts explains about unique composite non cluster index. Three records inserted successfully. When insert fourth record as same value it will be getting error. Note We can create unique composite non cluster index after inserted records to a table. If table have duplicate records we getting error while create unique composite non cluster index, because unique composite non cluster index not accept duplicate records. Way of checking Non Cluster Index in table We can find the index name and how many index created to a tables in SQL server. Go to Object Explore Database Table Table_Name Indexes Index names and corresponding fields. Conclusion This is article explains about non cluster index in simple way. I hope it is very help to students and fresher. Next article will be explains about internal structure of cluster and non cluster index in SQL server.