Every SQL Server developers used to think about performance. They expect their queries should be fast and they want to write efficient queries. Here is a small tip to improve the performance of your queries.
First thought to improve Performance is to create or modify or rebuild the indexes. Index are special handy objects for the sql developers to improve the performance. Creating an index on the table will improve the accessibility to the tables. Retrieving the values from the table becomes too easy. There are two types of index,
1. Clustered index(On creating primary key, the index will get created)
2. Non-clustered index.
In addtion to the above indexes, we are having another index called Covering index. It's a straight foward index. Considering a query is using 5 columns frequently, In that case we can create a composite index on the table involving all the 5 columns. This will avoid table scan and this will improve the performance of your table access.
Lets see a small code snippet,
drop table VenkatSample
create table VenkatSample(id int, [name] varchar(100),name1 varchar(100))
insert into VenkatSample values(1,'Venkat','Prabu')
insert into VenkatSample values(2,'suba','Venkat')
insert into VenkatSample values(3,'Arun','Arun')
insert into VenkatSample values(4,'Lakshmi','Lakshmi')
insert into VenkatSample values(5,'Santhi','Santhi')
insert into VenkatSample values(7,'Karthi','Karthi')
insert into VenkatSample values(8,'Lakshmi','Lakshmi')
insert into VenkatSample values(3,'Santhi','Santhi')
insert into VenkatSample values(89,'Karthi','Karthi')
select * from VenkatSample
select name,max(id) from VenkatSample group by id,name

Now, am creating an index on the table to force index scan instead of table scan.
create index VenkatIndex_IX on VenkatSample(id,[name])
select name,max(id) from VenkatSample group by id,name

1. Considering, am having only 2 columns in a table. Placing a covering index on the 2 columns will not have any major effect in your query performance.
2. Over usage or more covering index will have a reverse effect in the query performance. So, we should have a clear picture on the column usage in the queries.
3. In case of adverse effect, go back to your clustered or non clustered index on specific column.
Happy Learning!!!
Thanks and Regards,
Venkatesan Prabu .J
No comments:
Post a Comment