0

Possible Duplicate:
SQL: Using Select *

Hi everyone!

I wonder if it is really a bad idea to use the * symbol in stored procedure in SQL server? Is really better to write

SELECT
 NAME,
 AGE,
 OTHER_STUFFS

FROM
 TABLE

than

SELECT * FROM TABLE

For sure is only 3 columns in the table.. For performances is it better to enumerate every column? Tanks for help..

Community
  • 1
  • 1
bAN
  • 13,375
  • 16
  • 60
  • 93
  • Possible duplicates: http://stackoverflow.com/questions/65512/which-is-faster-best-select-or-select-column1-colum2-column3-etc, http://stackoverflow.com/questions/3388571/sql-using-select-closed – Abe Miessler Sep 07 '10 at 15:12
  • 4
    I'm quite sure this question was asked recently... – froadie Sep 07 '10 at 15:13

4 Answers4

2

While you might be using all the columns now it's possible (likely even) that the table will have columns added to it in the future. When this happens you will be selecting extra data and depending what you are doing with it this could cause problems.

Stolen from duplicate post Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc:

You may be willing to dismiss this as a minor cost, but realize that columns that you don't need still must be:

  1. Read from database
  2. Sent across the network
  3. Marshalled into your process
  4. (for ADO-type technologies) Saved in a data-table in-memory
  5. Ignored and discarded / garbage-collected
Community
  • 1
  • 1
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
0

I would say that it's only bad when you do something along the lines of

insert into Table1
select * from Table2

Because what if someone adds a column to Table2 or something like that.

It doesn't matter how you specify the necessary columns in a select statement, it won't affect performance.

Denis Valeev
  • 5,975
  • 35
  • 41
0

If you really are listing every column in the table, then the performance should be equivalent.

The trouble is when you later add more columns to that table, then they are getting selected by the stored procedure and not used unless you go back and update all your procs after each table change (I don't).

JohnFx
  • 34,542
  • 18
  • 104
  • 162
  • Not 100% - using `SELECT *` forces SQL Server to first inspect the table's definition to find out what columns there are. Specifying them directly skips this step. – marc_s Sep 07 '10 at 16:07
-7

Using SELECT * instead of selecting all columns doesn't make a difference at all. In fact, SELECT * could be a little bit faster, because less bytes have to be sent to the server to execute the command.

Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223
  • 5
    Wrong, it then has to generate the fieldnames at the database and that takes longer, if you have a join, then repeated data is being sent back which wastes server and network resources. – HLGEM Sep 07 '10 at 15:14
  • This is BS, and in Dutch we have a word for it: "bitneukerij" – Philippe Leybaert Sep 07 '10 at 15:15