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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Which way is better? Views or statement?

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-07-28 : 10:23:54
Can someone tell me which ways is better(fast)?

1) Select * from view1 WHERE (Orders.ShipCity = N'lyon')

view1:
SELECT Orders.*, [Order Details].*
FROM Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID

2) Here is statement using in one store procedure:
SELECT Orders.*, [Order Details].*
FROM Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID
WHERE (Orders.ShipCity = N'lyon')

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-07-28 : 12:01:29
try both in management studio with the execution plan turned on.

At a guess I think the execution plans will be identical.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-28 : 12:21:07
1 might be slower because of the view, if it's not compiled.

If it's compiled, then they should be the same

BUT

Even if they are different, it's negligible



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -