Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedures: Optimizing Queries
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 02/11/2001 :  18:50:08  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Philip writes "This is a two-parter:

If I'm calling a stored procedure from ASP, which of the following procs (entire code not shown) would execute faster, assuming that the fields containing "ID" are primary keys and indexed in the respective tables...

Version 1:

SELECT @currentStepID = currentStepID
FROM users
WHERE userID = @userID

SELECT @currentStepURL = stepURL
FROM steps
WHERE stepID = @currentStepID

Note: @currentStepID is a local variable, @userID is an input parameter, @currentStepURL is an output parameter

Version 2:

SELECT @currentStepURL = s.stepURL
FROM users u
JOIN steps s
ON u.currentStepID = s.stepID
WHERE u.userID = @userID

Note: @userID is an input parameter, @currentStepURL is an output parameter

Part II:

How can I use the SQL Query Analyzer to compare the above? I plugged in both queries and performed an "Execution Plan," but can you provide some more insight on comparing "I/O cost", "CPU cost", "Subtree cost", etc.?


Philip Misiowiec
Webficient LLC"

Most Valuable Yak

15732 Posts

Posted - 02/12/2001 :  09:56:22  Show Profile  Visit robvolk's Homepage  Reply with Quote
In general terms, the plan that provides the fewest physical reads will perform better, all else being equal. Next would be fewest logical reads. These are the slowest parts of the execution sequence. It's possible to write something that performs better overall with higher readings for either, but it would have fairly small results and tables involved; once the # of rows increases the performance will go down again.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000