Thursday, January 14, 2010

Use "With" clause to improve performance of your Query

WITH studentsM AS (
SELECT * FROM StudentsMaster
)
SELECT * FROM studentsM

if you are looking first time "With" clause in SQL then you will think that here studentsM is a temporary table and in next line "SELECT * FROM studentsM" we are retriving values from temporary table.

BUT ITS NOT CORRECT

In real "With" clause is very useful to improve performance of your query.

How: in our first statement its not crating Temporary table. It just giving name to select query and in second statement we are querying from that Name (above select query) means you need not to create a temporary table you just write any large sql query and give it name using with and later (in next of after next statement) we can query on it... Very Goood no..? It will improve your query Speed very much..


0 comments:

Post a Comment

 

About

Site Info

Information Source

SQL Server Copyright © 2009 Community is Developed by Dot Net Developer WebSite

/* tracking code by yahoo login */