Why is SELECT *
bad practice? Wouldn\'t it mean less code to change if you added a new column you wanted?
I understand that SELECT COUNT(*)
The asterisk character, "*", in the SELECT statement is shorthand for all the columns in the table(s) involved in the query.
The *
shorthand can be slower because:
SELECT *
over the wire risks a full table scanWhen using SELECT *
:
SELECT *
will hide an error waiting to happen if a table had its column order changed.SELECT *
is an anti-pattern:
It's acceptable to use SELECT *
when there's the explicit need for every column in the table(s) involved, as opposed to every column that existed when the query was written. The database will internally expand the * into the complete list of columns - there's no performance difference.
Otherwise, explicitly list every column that is to be used in the query - preferably while using a table alias.