Click here to Skip to main content
15,891,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
Is there any sql query analyzer tool from where I can check which way is better.


Regards
Seema
Posted

You can do a lot from within management studio, the third link posted by JF2015 is essential reading

If you've got the Northwind database, open a new query window against it and put in the following SQL

SQL
SELECT CustomerID, CompanyName
FROM dbo.Customers
WHERE City= 'London'


Now choose Query -> Display Estimated Execution Plan

The database engine will show you that for this query it will attempt to perform an Index Seek against the index named City

Now try the same thing with this SQL

SQL
SELECT * FROM  Orders O
WHERE ShipCity Like  '%London%'
ORDER BY OrderDate


You'll notice this time it's performing an Index Scan (80% of total query Cost) and a Sort (20%).

Depending on the amount of rows in the table, you would generally want to avoid a Scan. The engine has to analyse all the rows in the table to determine which rows qualify for your statement

http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/[^]

The execution plan window is a really useful part of SQL Server, you should get used to checking SQL statements here.
 
Share this answer
 
Comments
Espen Harlinn 29-Jan-11 4:50am    
5+ Nice additional info

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900