Friday, 17 March 2017

What is Table scan, covering index(clustered index scan), index query and index seek in Sql Server

create table EmployeeInfo
(
          Id int,
 Name varchar(200),
 Address varchar(200)
)

//Insert multiple record into table with single query

insert EmployeeInfo values(1,'Ashish','Chandigarh'),(2,'Pankaj','Delhi'),(3,'Verma','UP'),(4,'Rahul','Chandigarh'),(5,'Seema','Punjab'),(6,'Satish','LKO'),(7,'Ramesh','Patna')


Table scan-

Table scan is that in which select statement is fired on a table which don't have any clustered index.

exp -

select * from EmployeeInfo 




select * from EmployeeInfo where Id=1



Covering Index (Clustered index scan) -

Select statement is execute on that table which have clustered index. To get all records from the table in such manner to cover all indexes of a table known as Covering Index and query is known as index query 

Exp -

create table EmployeeInfo1
(
          Id int primary key,
 Name varchar(200),
 Address varchar(200)

)



insert EmployeeInfo1 values(1,'Ashish','Chandigarh'),(2,'Pankaj','Delhi'),(3,'Verma','UP'),(4,'Rahul','Chandigarh'),(5,'Seema','Punjab'),(6,'Satish','LKO'),(7,'Ramesh','Patna')



select * from EmployeeInfo1 




Index seek (Clustered index seek) 

Select query is execute to get a specific record from the table which have clustered index known as Clustered index seek.

select * from EmployeeInfo1 where Id=1










No comments:

Post a Comment