Difference between revisions of "Best Practices: MySQL"
From phpBB Development Wiki
(New page: ==Field Type== ===SIGNED vs UNSIGNED=== SIGNED should be used where a field might contain a negative number such as distances<br> UNSIGNED should be used where a field will '''never''' con...)
Latest revision as of 20:22, 10 October 2008
SIGNED vs UNSIGNED
SIGNED should be used where a field might contain a negative number such as distances
UNSIGNED should be used where a field will never contain a negative number such as unix timestamp or id fields
Use the correct size
You should always use the correct field type for the size of the value you will be inputting into it.
CHAR vs VARCHAR
CHAR should be used when a fixed number of character is expected such as an MD5 has which is always 32 characters.
VARCHAR should be used when an unknown number of characters is expected such as a name or email address
Character vs Numerical
When ever possible you should be storing a numerical value in a numeric field type and not a character field type.
For example dates and time can be stored as a unix timestamp. IP address can also be stored as an INT by using the ip2long()