Below given are some facts those can be used to optimize our query performance
- Unique Key: If there is no primary key defined on a table sql uses "Table Scan" operator.table scan operator reads records one by one until it gets required record, so this operator is costly if table having large number of rows.
When we create primary key on table it improve performance drastically. As displayed in picture.
- Scan Vs Seek: If we've clustered / non clustered index on table then sql uses 'Index Scan' or 'Index Seek' operators.Index Scan : Touches every row whether it is qualified or not, start to end. So cost associated with this search is proportional total number of rows.
This scan is right choice if table is small or most of the rows are qualified for condition of query.
Index Seek : Index seek touches only rows / pages those are qualified for condition of query.
So, if we provide some condition sql prefer to choose 'Index Seek', Even if condition provided result record number is large then optimizer change the plan uses Scan instead of Seek.
This is right choice if table having large number of rows or qualified rows count is very much smaller(few) compare to all rows.


