Database fields and their attributes

As mentioned a database field is a container for a single piece of data such as a surname, a price or a number. Each of those examples is a different type of data. They could all be stored as text but there are advantages to making sure they are held as what they are. The most common types of field have these attributes:

The general rule is to use the smallest and simplest field which will successfully hold your data. For example, when storing a person's first name where the longest likely content is maybe 20-30 characters don't allocate 50 characters as this will waste space in the database and slow it down as well. If the numbers you want to hold cannot be negative then make sure you use an unsigned data type as then the upper limit will be higher (or maybe you can use a smaller data type). If numbers will always be whole (no decimal points) then there is no need to use floating point or decimal field types (float, single, double etc.).

submit to reddit Delicious Tweet