Groups | Blog | Home
all groups > sql server (alternate) > january 2005 >

sql server (alternate) : Optimal SQL



teddysnips NO[at]SPAM hotmail.com
1/7/2005 7:23:10 AM
Please excuse what is probably a no-brainer, but here goes.

Is there any difference, in terms of performance or any other pertinent
factor, between:

SELECT * FROM tblCustomers INNER JOIN tblCustomerOrders ON
tblCustomers.fldCustomerID = tblCustomerOrders.fldCustomerID

and

SELECT * FROM tblCustomers, tblCustomerOrders WHERE
tblCustomers.fldCustomerID = tblCustomerOrders.fldCustomerID

I note that if I type the latter into the SQL pane in a Data window,
SQL Server replaces it with the former.

TIA

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk
Nigel Rivett
1/7/2005 10:00:21 AM
Should give the same query plan.

Nigel Rivett
www.nigelrivett.net

*** Sent via Developersdex http://www.developersdex.com ***
David Portas
1/7/2005 4:00:35 PM
If you examine the execution plans in Query Analyzer you will find the two
statements are identical. For INNER JOINs either syntax is legal and which
you use really comes down to readability and personal preference.

[quoted text, click to view]

One reason to avoid GUI query tools is that they tend to mess with the
formatting and syntax of your code. My advice is to use a proper query
editor, like Query Analyzer. In the long run you'll find you can write
better code much quicker that way.

--
David Portas
SQL Server MVP
--

teddysnips NO[at]SPAM hotmail.com
1/8/2005 3:38:36 AM
[quoted text, click to view]
Thanks to you and Nigel. I agree with your distress at the way the GUI
tool in SQL Server messes with code - I like to have things laid out
just so, and it's no business of SQL Server to do it's nanny thing.
But that's Microsoft for you, the company that brought us Office
Assistant.

Unfortunately, for very involved outer joins with multiple tables, I'm
just not expert enough to craft the thing in QA, or rather I like to
see a graphical representation of the table relations. But I suppose I
could write it in QA, then paste it into a Data pane and see what the
GUI made of it.

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk


--
We are what we repeatedly do. Excellence, then, is not an act, but a
habit - Aristotle

Those heights by great men reached and kept
Were not obtained by sudden flight,
But they, while their companions slept
Were toiling upward in the night
- Longfellow
AddThis Social Bookmark Button