devxlogo

Do Not Use the * with the SELECT Statement in Production Code

Do Not Use the * with the SELECT Statement in Production Code

When * is used in a select query, it returns all the columns in a table. This approach can be used in a development or testing environment, but it should not be used in the production code.
The main reason it should not be used is that the structure of the table the statement references may change over time and when this happens, there is potential for breaking the code that worked before the table was modified.
Let’s take an example. Suppose Movie table has MovieName, Year, and Review columns:

 SELECT * from Movie

Should be replaced by:

 SELECT MovieName, Year, Review

Specifying the column names also makes code maintenance easier. Another person will not have to guess what the statement returns.

devx-admin

Share the Post: