Groups | Blog | Home
all groups > sql server programming > january 2007 >

sql server programming : necessary help-difference


Nassa
1/6/2007 10:16:24 PM
Hello Everyone,

Does it make difference in query costs(query performance),if add all
columns of 2tables or choose just some columns of 2 tables?
which one is the best?Y?

Thanks,
Nassa
Nassa
1/7/2007 1:07:03 AM
Uri Dimant,

Thank you for your answer.
it is better if I have 2 tables and make a query from join of those or
it is better if I join all column of 2 tables and then make a query
from them?
Which one help me in query performance?please give me reason.

Thanks,
Nassa




[quoted text, click to view]
Nassa
1/7/2007 1:46:39 AM
Uri dimant,

for example I have 2 tables:
N1(c1,c2,c3)
N2(c4,c5,c7,c8)

I want to make query from these 2 tables:
I have 2 solutions:
1-make a view that contain all of these columns:
Vw(c1,c2,c3,c4,c5,c7,c8)
then make query from this view
SELECT N1.c1,n1.c3,n2.c4,n2.c5
[quoted text, click to view]
2-make query directly from these 2 tables:
SELECT N1.c1,n1.c3,n2.c4,n2.c5
[quoted text, click to view]

Now pls tell me which one is better?

Thanks,
Nassa







[quoted text, click to view]
Nassa
1/7/2007 2:15:03 AM
Uri Dimant,

which one is better and have more performance?

thanks,
Nassa



[quoted text, click to view]
Uri Dimant
1/7/2007 9:46:03 AM
Nassa
Well , it depends on your bussines requirements. Select only those columns
that you need. Moreover, it may helps you in terms of permormance , means if
you have covering indexs on some column which include in select statement
(getting index seek, rather bookmarks lookup)



[quoted text, click to view]

Erland Sommarskog
1/7/2007 11:19:02 AM
Nassa (nassim.czdashti@gmail.com) writes:
[quoted text, click to view]

As long as the view is a plain-vanilla view there can be no difference,
because view is not a storage. The view is just like a macro, and the
query executed is the same as the original query.

You can materialise a view by creating a clustered index on it. To this,
the view needs to fulfil a number of conditions. In this case, there may
be a performance difference, if the optimizer to use the view instead.
But normally you would not create an indexed view for a query like the
one above. Indexed views are often used for aggregations.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Uri Dimant
1/7/2007 11:23:35 AM
Nassa
I'm not sure understood you

This example takes CustomerName from Customer table and OrderId from
Orders

SELECT CustomerName,OrderId FROM Orders JOIN Customer ON
Orders.CustomerId=Customer.CustomerId




[quoted text, click to view]

Uri Dimant
1/7/2007 11:53:55 AM
It is upt to you. Views are good in terms of security


[quoted text, click to view]

Uri Dimant
1/7/2007 12:22:51 PM
I have not seen any differences in terms of performance


[quoted text, click to view]

AddThis Social Bookmark Button