Based on this question here Selecting NOT NULL columns from a table One of the posters said
you shouldn’t use SELECT * in production.
My Question: Is it true that we shouldn’t use Select * in a mysql query on a production server? If yes, why shouldn’t we use select all?
Most people do advise against using
SELECT *in production, because it tends to break things. There are a few exceptions though.SELECT *fetches all columns – while most of the times you don’tneed them all. This causes the SQL-server to send more columns than
needed, which is a waste and makes the system slower.
SELECT *, when you later add a column, the old query will alsoselect this new column, while typically it will not need it. Naming
the columns explicitly prevents this.
SELECT *queries also tend to grab the rowsand use column order to get the columns – which WILL break your code
once columns are injected between existing columns.
SELECT *might behave differently when the table column order is modified.But there are exceptions, for example statements like these:
A query like that takes rows from table, and inserts them into table_history. If you want this query to keep working when new rows are added to table AND to table_history,
SELECT *is the way to go.