Database Tips (@Database_Tips) profile picture

Practical “byte” sized database tips!

United States
Joined February 2020
Looking for an easy way to check disk space in Microsoft SQL Server? Look no further! https://teapawt.net/t.co/qRtO42qwaE
1
Wow! That’s impressive. Wish I started that early!
1
What about non-base-10 currencies you ask? According to Wikipedia there are only 2 in existence and they are only theoretically non-decimal so this advice applies to every currency.
1
Going back to our donut example, this math would then be 12 donuts * 110 cents = 1,320 cents. If we then wanted to display this in $, we would simply divide by 100.0 and format the right number of decimals.
1
Our suggestion: Store the lowest denomination as an integer. For example, with USD storing all money values as cents in an integer column.
1
Another example: Selling 12 gourmet donuts for 1.10 each. In a Python shell the result is 13.200000000000001 which cannot be accurately represented as base-10 without rounding.
1
Floats can't calculate base-10 numbers accurately without rounding. For example Dividing $1 / 3.0 would yield .333333...
1
Don't EVER use floats to store money! Heres why, and what you should do instead:
1
1
Naming convention is always a hot topic... We think simplicity and consistency wins out! #databases #programming #software
1
Need a quick diagramming tool? Try dbdiagram! dbdiagram.io #dbdiagram #dev #database