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
 General SQL Server Forums
 New to SQL Server Programming
 SELECT *

Author  Topic 

Trio
Starting Member

2 Posts

Posted - 2009-09-03 : 01:34:59
I'm in a bit of a quandary here.

I need to select all the columns from my table so I was using SELECT * .... However, using * is inflexible as the data cannot be directly manipulated (e.g. can't use aliases).

Is it bad practice to manually enter each column from a table in a SELECT statement? It seems long and ugly. Is it slower too?

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-09-03 : 01:43:54
It is the best practise to write columns names in select List, rather than *.
It can take time to write column list, but while retunring result it can be faster, since SQL Server will retrun only required data.

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

Trio
Starting Member

2 Posts

Posted - 2009-09-03 : 02:02:41
Thanks.
Go to Top of Page

saifullah.farooqui
Starting Member

1 Post

Posted - 2009-09-03 : 02:16:39
Also in featur you can easly add more column to you table which will never effect you existing Query,
Go to Top of Page

ahmad.osama
Posting Yak Master

183 Posts

Posted - 2009-09-03 : 05:02:16
quote:
Originally posted by Trio

I'm in a bit of a quandary here.

I need to select all the columns from my table so I was using SELECT * .... However, using * is inflexible as the data cannot be directly manipulated (e.g. can't use aliases).

Is it bad practice to manually enter each column from a table in a SELECT statement? It seems long and ugly. Is it slower too?


you can use RedGate's SQLPROMPT for writing queries.....
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-03 : 05:04:57
quote:
Originally posted by ahmad.osama

quote:
Originally posted by Trio

I'm in a bit of a quandary here.

I need to select all the columns from my table so I was using SELECT * .... However, using * is inflexible as the data cannot be directly manipulated (e.g. can't use aliases).

Is it bad practice to manually enter each column from a table in a SELECT statement? It seems long and ugly. Is it slower too?


you can use RedGate's SQLPROMPT for writing queries.....


Why?
You can make use of SSMS in this case

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-03 : 05:13:40
quote:
Originally posted by Mangal Pardeshi

It is the best practise to write columns names in select List, rather than *.
It can take time to write column list, but while retunring result it can be faster, since SQL Server will retrun only required data.

Mangal Pardeshi
http://mangalpardeshi.blogspot.com


And in case of NOT using * there is no need for sql to identify ALL column names by using some systables.
So the query has less overhead and is wasting no time.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-03 : 05:14:55
You can use * though for ad hoc queries. It is only important for queries in production.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -