If you want to store an employee number, for which the maximum possible value is 500,000, the optimum datatype is MEDIUMINT UNSIGNED (which occupies 3 bytes). If you are storing it as INT, which occupies 4 bytes, you are wasting a byte for each row.
If you want to store the first name, for which the length is varying and the maximum possible value is 20, it is optimal to declare it as varchar(20). If you are storing it as char(20), and just a few names are 20 characters long while the remaining are less than 10 characters long, you are wasting space of 10 characters.
While declaring varchar columns, you should consider the length. Though varchar is optimized on-disk, while loading into memory, it occupies the full length. ...
With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, interactive tutorials, and more.