Badly Named Columns

Pretend you are dealing with an e-commerce site. The orders are stored in two tables. One table is the order table, containing the customer information and overall order information. The other is an item table, which contains information on each item in the order.

Pretty standard stuff, right?

Now, let's pretend the orders table has a field named "total". What does this field contain?

I bet you said "It contains the total order amount." You probably know that an order total is calculated by taking the Item Price * Quantity for all items in the order and adding them together. ( this is called a sum, and is basic math )

A few of you might say that the site doesn't need to store the order total. You can create a view that contains the sale price, and is calculated from the items table. It's actually pretty easy to do this:


select orderID, sum(salesprice*quantity) as count
from items
group by orderID

( That code is off the cuff and completely untested ). I'd agree with those that thought this far through it.

Back to the original question: How many said that "orders.total" probably stores the total dollar amount of unfilled items? The app I'm working on is using the column to store that. It took me about an hour of code reviews to figure it out.

If the field was named "UnfilledTotal" or something similar, it would have been much more obvious.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.