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.

See also  5 Tips for Choosing the Right Medical Software for Your Practice

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist