Question

e.g. Barcelona - Madrid 4:1 or Arsenal - Chelsea 2:0

Which data types are good to represent 4:1 and 2:0 etc?

The options that come to mind are:

  1. Two smallints
  2. One decimal (i.e. 4.1 and 2.0)
  3. One point (i.e. 4,1 and 2,0)

Anything else? How'd you do it? It must be easy to retrieve who's won the game and what the difference in goals was, which makes me tend to the first option but maybe there is more (memory considerations...)?

Was it helpful?

Solution

It is probably best to store the score as two separate values. The memory and time differences between the different options you've suggested are just too small to care about unless your database is HUGE. Two separate values will make it easier to write queries without needing to include logic that parses out the two values in every query.

Also, you could include additional columns for the spread, the winner, etc. if you like. Keeping more data in the table makes for slower updates/inserts, but simpler and faster read queries (because the winner and spread are already calculated). Assuming this is for a sports website or something similar, you'll probably have way more reads (i.e. visitors to the site) on a given day than inserts/updates (new games that were played).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top