File Under: Programming, Web Basics

SQL Basics: Four Reasons Never to Select All

Select errorHave you ever written a database call that went something like… select * from posts where id=3;? We probably all have, but it’s bad for several reasons. Four of them, according to a programmer that goes by pizza_milkshake.

To database administrators and advanced programmers, this may not come as news. Even many seasoned coders could use a reminder not to be lazy.

pizza_milkshake’s Four Reasons Not to Select All

  1. If you include the field names, your code is self-documenting
  2. When a field name changes, you want to know with a query error, not later
  3. Asking for more than you need is just wasting resources
  4. Without naming the fields, you can’t be certain of the order you’ll receive them

I hope these reasons are good enough to encourage your next query to not start select *.

See also: