I'm working with an SQL database right now, and this has always made me curious, but Google searches don't turn much up: Why the strict data types?
I understand why you'd have a few different data types, for example like how differentiating between binary and plain text data is important. Rather than storing the 1s and 0s of binary data as plaintext, I now understand that it's more efficient to store the binary data as its own format.
But what I don't understand is what the benefit is of having so many different data types:
- Why
mediumtext
,longtext
, andtext
? - Why
decimal
,float
, andint
? - etc.
What is the benefit of telling the database "There'll only be 256 bytes of plain text data in entries to this column." or "This column can have text entries of up to 16,777,215 bytes"?
Is it a performance benefit? If so, why does knowing the size of the entry before hand help performance? Or rather is it something else altogether?
decimal
,float
, andint
types, what would you expect1 / 3
to do? What about1.0 / 3.0
? Could you be confident that when you dividecolumnA
bycolumnB
that you'll get the results you expect?