Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL select * vs. selecting specific columns [duplicate]

Tags:

sql

sql-server

I was wondering which is best practice. Lest say I have a table with 10+ columns and I want to select data from it.

I've heard that 'select *' is better since selecting specific columns makes the database search for these columns before selecting while selecting all just grabs everything. On the other hand, what if the table has a lot of columns in it?

Is that true?

Thanks

like image 810
developer82 Avatar asked Dec 20 '22 20:12

developer82


1 Answers

It is best practice to explicitly name the columns you want to select.

As Mitch just said the performance isn't different. I even heard that looking up the actual columns names when using * is slower.

But the advantage is that when your table changes then your select does not change when you name your columns.

like image 104
juergen d Avatar answered Dec 22 '22 08:12

juergen d